zoukankan      html  css  js  c++  java
  • 非模态对话框的销毁

    非模态对话框相对于模态对话框,它的创建和销毁过程和模态对话框有一点区别,先看一下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);

  • 相关阅读:
    STL源码剖析:迭代器
    STL源码剖析:配置器
    [bzoj3940][Usaco2015 Feb]Censoring
    [bzoj2212][Poi2011]Tree Rotations
    [bzoj2733]永无乡&&[bzoj3545]Peaks
    挂个AC自动机
    [bzoj4237]稻草人
    莫比乌斯反演定理证明
    斜率优化dp学习
    备忘
  • 原文地址:https://www.cnblogs.com/Hisin/p/2378043.html
Copyright © 2011-2022 走看看