3

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?

Mr. Boy
  • 57,008
  • 88
  • 294
  • 540

1 Answers1

3
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

Community
  • 1
  • 1
aJ.
  • 33,420
  • 21
  • 82
  • 127