Lifecycle of controls on a composite control

Lifecycle of controls on a composite control

Post by Gary F » Sun, 12 Feb 2006 00:12:38


I have an ATL composite control, which will run in IE, hosting a
variety of controls. Some are windows common controls on the dialog at
design time, some are third-party activex controls on the dialog at
design time, and some are objects which need to be dynamically created
at runtime.

I don't really know the correct procedure when using wrappers or
creating instances. In addition, I don't really understand how
lifecycle works with UI Activate and UI Deactivate and the events fired
versus the actual creation and deletion of my ATL composite control.
(Is there a good book/article on this particular subject?)

1) For the common controls on the dialog, I use WTL convenience
wrappers. In UML terms, I declare them as composite members, eg
WTL::CButton m_button (versus aggregation, WTL::CButton* m_pButton) in
the class header file. I attach them in OnInitDialog() and detach them
in OnDestroy(). Correct?

2) For the activex controls on the dialog, I use the smart pointer
generated via the #import statement. I declare them as composite
members in the class header file. I use GetDlgControl() to fill the
smart pointer in OnInitDialog() and then call Detach() in OnDestroy().
Correct?

3) For the dynamically created third-party controls, I use the smart
pointers from #import. I declare them as composite members (ie,
C3pControPtr m_spCtrl) in the class header file. In OnInitDialog(), I
use m_spCtrl.CreateInstance() and in OnDestroy(), I do m_spCtrl = NULL.
Is this correct?


Also, how do I find out if I'm leaking references? Viewing the ROT?

All help appreciated.

Gary
 
 
 

Lifecycle of controls on a composite control

Post by Alexander » Sun, 12 Feb 2006 03:15:45

See inline.

--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD
email: XXXX@XXXXX.COM
MVP VC FAQ: http://www.yqcomputer.com/
=====================================




So far so good.


Detach causes the interface pointers, hence the COM objects, to be
leaked. Don't call Detach - call .Release (not ->Release) to dispose
of your references.


Are these ActiveX Controls? In that case you need to host them as
well, using CAxWindow. See the following KB article:

Q218442: "How to add ActiveX controls to an ATL composite control
programmatically in Visual C++"
http://www.yqcomputer.com/