创建
CVolSetDlg*m_pVolDlg=NULL;
m_pVolDlg=newCVolSetDlg;
m_pVolDlg->Create(IDD_DLG_VOL);
m_pVolDlg->ShowWindow(SW_SHOW);
销毁
[1]:
重载OnCancel函数
void CXX::OnCancel()
{
//TODO: Add your specialized code here and/or call the base class
CDialog::OnCancel();
}
[2]:
屏蔽掉CDialog::OnCancel();,并添加
DestroyWindow();
如下:
void CXX::OnCancel()
{
//TODO: Add your specialized code here and/or call the base class
DestroyWindow();
//CDialog::OnCancel();
}
[3]:
添加消息WM_DESTROY
在响应函数中添加要释放资源的操作:
void CXX::OnDestroy()
{
//release resourse ...
CDialog::OnDestroy();
}
[4]:
重载PostNcDestroy函数,添加delete this;
void CXX::PostNcDestroy()
{
//TODO: Add your specialized code here and/or call the base class
deletethis;
CDialog::PostNcDestroy();
}
因为非模态对话框一般是通过new来创建的;
CXX *pXXDlg=new CXX();
所以在释放资源时必须要用delete来删除
如果是在外部删除的,那么不需要在CXX::PostNcDestroy中添加delete this;