tags:

views:

91

answers:

1

Lets say in a dialog, we dynamically create a variable number of CWnds... like creating a and registering a CButton every time the user does something/

Some pseudo-code...

class CMyDlg : public CDialog
{
 vector<CWnd *> windows;

 void onClick()
 {
  CButton *pButton = new CButton(...);
  //do other stuff like position it here
  windows.push_back(pButton);
 }
}

Do I need to explicitly delete them or will MFC do it? If I have to, would it be in the destructor as normal, or are there any special things to avoid breaking MFC... making sure I don't delete the objects while the HWNDs are still in use for example?

+1  A: 
CButton *pButton = new CButton(...);

These are C++ objects, which needs to be deleted explicitly. (Where as Main frame windows and Views are self destructed).

You can refer the detailed answer ( by me) Destroying Window Objects

aJ
Thanks for the link, +1 for both :)
John