解决 Warning: calling DestroyWindow in CWnd::~CWnd OnDestroy or PostNcDestroy in derived class will not be called

解决 Warning: calling DestroyWindow in CWnd::~CWnd OnDestroy or PostNcDestroy in derived class will not be called
  出现上面Warning,原因是,调用窗口类析构的时候,窗口对象还没有销毁。具体表现在,当在一个窗口中生成另外一个窗口CTestDlg 时:
       
CTestDlg  * pDlg  =   new  CTestDlg();
pDlg
-> Create(IDD_DIALOG_TEST, this );
pDlg
-> ShowWindow(TREU):

//  结束时
delete pDlg;
pDlg 
=  NULL;

  这样的写法就会出现上面的warning,正确的做法如下:
//  结束时
if (pDlg)
{
  pDlg
->DestoryWindow();
  pDlg 
= NULL;
}


// 在后生成的窗口类中加如下代码
void  CTestDlg::PostNcDestroy()
{
    
// TODO: 在此添加专用代码和/或调用基类
    delete this;//这个一定要
    CDialog::PostNcDestroy();
}


       

你可能感兴趣的:(解决 Warning: calling DestroyWindow in CWnd::~CWnd OnDestroy or PostNcDestroy in derived class will not be called)