MFC: deleting dynamically created CWnd objects

Let's talk in a dialog box, we dynamically create a variable number of CWnds ... for example, create a and register CButton every time the user does something /

Some pseudo codes ...

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 there be an MFC? If I need it, it would be in the destructor as usual, or are there some special things not to violate the MFC ... making sure that I do not delete objects while the HWND is still in use, for example?

+3
source share
1 answer
CButton *pButton = new CButton(...);

These are C ++ objects that need to be explicitly deleted. (Where in the case when the windows of the main window and views are independently destroyed).

() Window

+3

Source: https://habr.com/ru/post/1748500/


All Articles