非模态对话框的销毁

非模态对话框相对于模态对话框,它的创建和销毁过程和模态对话框有一点区别,先看一下MSDN的原文:

When you implement a modeless dialog box, always override the OnCancel member function and call DestroyWindow from within it. Don’t call the base class CDialog::OnCancel, because it calls EndDialog, which will make the dialog box invisible but will not destroy it. You should also override PostNcDestroy for modeless dialog boxes in order to delete this, since modeless dialog boxes are usually allocated with new. Modal dialog boxes are usually constructed on the frame and do not need PostNcDestroy cleanup.

所以:

一、 在非模态对话框中override OnOK和OnCancel

protected:

    virtual void OnOK();

    virtual void OnCancel();

 

void CYourDlg::OnOK()

{

    this->DestroyWindow();

}

void CYourDlg::OnCancel()

{

    this->DestroyWindow();

}

 

二、 在非模态对话框中override PostNcDestroy

protected:

    virtual void PostNcDestroy();

 

void CYourDlg::PostNcDestroy()

{

    CDialog::PostNcDestroy();

    delete this;

}

非模态对话框的创建代码一般如下:

CYourDlg *pDlg=new CYourDlg;
pDlg->Create(IDD_DLG_YOUR, this);
pDlg->ShowWindow(SW_SHOW);

转载于:https://www.cnblogs.com/Hisin/archive/2012/03/03/2378043.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值