I create a modeless dialog by using new operator during the application is runing. And I want to destroy it until the user quit the application.
But this window is destroyed automatically by MFC,and if call DestroyWindow somewhere an error will occur.
Of course, if cancel the code below:Code:CMyDialog::PostNcDestroy() { // this will be called by the frame firstly! CDialog::PostNcDestroy(); delete this; } CMyView::OnCreateDialog() { if(m_pDlg==NULL) { m_pDlg=new CMyDialog; m_pDlg->Create(IDD_MYDIALOG); m_pDlg->ShowWindow(SW_SHOW); } } CMyView::OnDsetroy() { //this call will be " Unhandled exception" error if(m_pDlg!=NULL) m_pDlg->DestroyWindow(); }
there will be nothing error.Code://if(m_pDlg!=NULL) m_pDlg->DestroyWindow();
But I don't want the frame do free work for me.
I prefer that all the resource allocated by myslef is freed by myself also.
So how to destroy the dialog correctly?
Thanks!




Reply With Quote