zoukankan      html  css  js  c++  java
  • 非模态窗口的创建方法

    粘贴一些关键代码(IN  FILE_MYBOLE):

    CMyboleView窗口类中

    void CMyboleView::OnMenuDialog()
    {
        // TODO: 在此添加命令处理程序代码
        //非模态对话框的使用,要更改 OnOK 这个虚函数
        if(m_pDlg)
        {
            m_pDlg->SetActiveWindow();
        }
        else
        {
            m_pDlg = new CTestDlg(this);
            m_pDlg->Create(IDD_ONE_DLG, this);
            m_pDlg->ShowWindow(SW_SHOW);
        }
    }

    初始化指针CTestDlg类的对象指针为NULL

    CMyboleView::CMyboleView()
    {
        // TODO: 在此处添加构造代码
        m_pDlg = NULL;
    }

    然后处理OK或者Cancel按钮

    Cancel

    void CTestDlg::OnCancel()
    {
        // TODO: 在此添加专用代码和/或调用基类
        //CWnd *p1 = GetParent();
        //CWnd *p2 = m_pParentWnd;
        //CWnd *p3 = GetParentFrame();
        //CWnd *p4 = GetParentOwner();
        //CWnd *p5 = GetOwner();
        
        //获取CTestDlg的指针有两种方法,都可以用,但是必须用m_pParentWnd,不能用GetParent
        //方法一:
        /*CMyboleView *pFather = (CMyboleView *)m_pParentWnd;
        pFather->m_pDlg = NULL;*/
    
        //方法二:
        ((CMyboleView *)m_pParentWnd)->m_pDlg = NULL;
    
        DestroyWindow(); //删除对话框,但没有删除对话框对象
    }

    OK

    void CTestDlg::OnOK()
    {
        // TODO: 在此添加专用代码和/或调用基类
    
        ((CMyboleView *)m_pParentWnd)->m_pDlg = NULL;
        DestroyWindow(); //删除对话框,但没有删除对话框对象
    }

    最后重写PostNcDestroy用来真正的销毁CTestDialog对象

    void CTestDlg::PostNcDestroy()
    {
        // TODO: 在此添加专用代码和/或调用基类
        delete this;
        CDialogEx::PostNcDestroy();
    }
  • 相关阅读:
    debian 9安装细节
    gnome环境设置
    Linux之crontab定时任务
    独显切换进入图形界面思路
    pycharm多行注释
    如何在cmd中运行.py文件
    如何在 PyCharm 中设置 Python 代码模板
    在R中使用Keras和TensorFlow构建深度学习模型
    kubernetes cert-manager installation
    Simple way to create a tunnel from one local port to another?
  • 原文地址:https://www.cnblogs.com/develop-me/p/5744837.html
Copyright © 2011-2022 走看看