开发者

MFC: Deleting dynamically created CWnd objects

开发者 https://www.devze.com 2023-01-02 11:59 出处:网络
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/

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?


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

0

精彩评论

暂无评论...
验证码 换一张
取 消