非模式对话框的问题

223 阅读1分钟

对于非模态窗口,必须重载OnCancel函数,在函数中调用DestroyWindows()方法,且不能调用基类的函数。因为基类函数中调用的是 EndDialog()方法。(因为EndDialog是关闭模态对话框时调用的)而OnClose()也会调用OnCancel()方法。另外想通过OnOK关闭对话框,也必须同样处理,不能直接用默认方法

非模态对话框销毁过程OnClose()->OnCancel()->DestroyWindow()->OnDestroy()->OnNcDestroy()->PostNcDestroy()

所以得重载OnCancel()和PostNcDestroy()

  1. void CxxxDlg::OnCancel()

  2. {

  3. DestroyWindow();

  4. }

  5.  

  6. void CxxxDlg::PostNcDestroy()

  7. {

  8. CDialogEx::PostNcDestroy();

  9. delete this;

  10. }