对于非模态窗口,必须重载OnCancel函数,在函数中调用DestroyWindows()方法,且不能调用基类的函数。因为基类函数中调用的是 EndDialog()方法。(因为EndDialog是关闭模态对话框时调用的)而OnClose()也会调用OnCancel()方法。另外想通过OnOK关闭对话框,也必须同样处理,不能直接用默认方法
非模态对话框销毁过程OnClose()->OnCancel()->DestroyWindow()->OnDestroy()->OnNcDestroy()->PostNcDestroy()
所以得重载OnCancel()和PostNcDestroy()
-
void CxxxDlg::OnCancel()
-
{
-
DestroyWindow();
-
}
-
-
void CxxxDlg::PostNcDestroy()
-
{
-
CDialogEx::PostNcDestroy();
-
delete this;
-
}