Click here to Skip to main content
15,920,031 members
Home / Discussions / ATL / WTL / STL
   

ATL / WTL / STL

 
GeneralRe: STL - map problem Pin
Paul Ranson21-May-04 7:50
Paul Ranson21-May-04 7:50 
GeneralRe: STL - map problem Pin
ra_sasi21-May-04 11:16
ra_sasi21-May-04 11:16 
GeneralWTL autodelete Pin
AstroDogDog20-May-04 9:57
AstroDogDog20-May-04 9:57 
GeneralRe: WTL autodelete Pin
Jörgen Sigvardsson23-May-04 11:23
Jörgen Sigvardsson23-May-04 11:23 
GeneralRe: WTL autodelete Pin
AstroDogDog23-May-04 11:27
AstroDogDog23-May-04 11:27 
GeneralRe: WTL autodelete Pin
Jörgen Sigvardsson24-May-04 8:01
Jörgen Sigvardsson24-May-04 8:01 
GeneralRe: WTL autodelete Pin
AstroDogDog24-May-04 9:37
AstroDogDog24-May-04 9:37 
GeneralRe: WTL autodelete Pin
Jörgen Sigvardsson24-May-04 10:40
Jörgen Sigvardsson24-May-04 10:40 
If you want autodeletion of WTL common control wrappers (CButton et al), here's some code which will do what you want:
template <typename T> 
class CSelfDeleteWindow : public CWindowImpl<CSelfDeleteWindow, T> {
   typedef CSelfDeleteWindow<T> ThisClass;
  
public:
   DECLARE_WND_SUPERCLASS(NULL, T::GetWndClassName())
 
   BEGIN_MSG_MAP(ThisClass)
   END_MSG_MAP()
 
   CSelfDeleteWindow(T& wnd) {
      ATLVERIFY(SubclassWindow(wnd));
      wnd.Detach();
   }
 
   void OnFinalMessage(HWND hWnd) {
      delete this;
   }
};
Then use it like this:
CButton btn;
btn.Create(*this,  CRect(0, 0, 100, 100), _T("Yo yo"), WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON);
new CSelfDeleteWindow<CButton>(btn);
As you can see, no control data can be in the control which you are wrapping, since the original object is detached inside the constructor of CSelfDeleteWindow. This doesn't matter much in the common control case as you only get opaque handles to them anyway - nothing is lost.

In the case of non common control classes as defined in atlctrlx.h, all you need to do is add your own thin wrapper class. If you look at CBitmapButton, you'll see that it is only a very thin wrapper around CBitmapButtonImpl. In this case, provide your own CBitmapButton class, which overrides OnFinalMessage(HWND) and deletes this.

For everything else (stuff that you've written with the use of CWindowImpl somewhere in your inheritance hierarchy), you just have to override OnFinalMessage(HWND) and delete this.

--
Booohoo!
GeneralRe: WTL autodelete Pin
AstroDogDog24-May-04 11:07
AstroDogDog24-May-04 11:07 
GeneralRe: WTL autodelete Pin
Jörgen Sigvardsson24-May-04 11:27
Jörgen Sigvardsson24-May-04 11:27 
GeneralRe: WTL autodelete Pin
AstroDogDog24-May-04 11:32
AstroDogDog24-May-04 11:32 
Generalsizeof operator Pin
rohit.dhamija19-May-04 21:34
rohit.dhamija19-May-04 21:34 
GeneralRe: sizeof operator Pin
Michael Dunn20-May-04 5:26
sitebuilderMichael Dunn20-May-04 5:26 
GeneralRe: sizeof operator Pin
Jörgen Sigvardsson23-May-04 11:34
Jörgen Sigvardsson23-May-04 11:34 
GeneralRe: sizeof operator Pin
Michael Dunn23-May-04 16:29
sitebuilderMichael Dunn23-May-04 16:29 
GeneralC# SessionId to HINTERNET Pin
VictorPr19-May-04 21:22
VictorPr19-May-04 21:22 
Generalamazon upload need help... Pin
Sumit Kapoor19-May-04 19:59
Sumit Kapoor19-May-04 19:59 
GeneralRe: amazon upload need help... Pin
Steve S19-May-04 22:29
Steve S19-May-04 22:29 
GeneralRe: amazon upload need help... Pin
Sumit Kapoor19-May-04 22:47
Sumit Kapoor19-May-04 22:47 
GeneralRe: amazon upload need help... Pin
Steve S20-May-04 4:34
Steve S20-May-04 4:34 
GeneralRe: amazon upload need help... Pin
Sumit Kapoor20-May-04 4:42
Sumit Kapoor20-May-04 4:42 
Questionhow to diasable a button Pin
mike shen19-May-04 16:37
mike shen19-May-04 16:37 
Generalusing for_each Pin
paulb19-May-04 15:13
paulb19-May-04 15:13 
GeneralRe: using for_each Pin
valikac19-May-04 18:36
valikac19-May-04 18:36 
GeneralRe: using for_each Pin
Andrew Walker19-May-04 22:10
Andrew Walker19-May-04 22:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.