非模態對話框需要重載OnCanel方法, 并調用DestroyWindow, 且不能調用基類的OnCanel
重載PostNcDestroy, 需要delete掉this指針
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CDlgTest)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
virtual void PostNcDestroy(); //}}AFX_VIRTUAL
// Implementation
protected:
// Generated message map functions
//{{AFX_MSG(CDlgTest)
virtual void OnOK(); virtual void OnCancel(); //}}AFX_MSG
void CDlgTest::OnOK()
{
// TODO: Add extra validation here
}
void CDlgTest::OnCancel()
{
DestroyWindow();
}
void CDlgTest::PostNcDestroy()
{
// TODO: Add your specialized code here and/or call the base class
CDialog::PostNcDestroy();
delete this;
}