非模态对话框需要重载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;

}