zoukankan      html  css  js  c++  java
  • VS2005 动态添加对话框并添加事件响应,添加子对话框

    1. 资源里面insert dialog。

    2. 右键点击对话框资源,选择:Add Class。

    3. 添加了CToolBarDialog.h, CToolBarDialog.cpp两个文件。

    4. 在CToolBarDialog.h里的最下面添加extern CToolBarDialog* g_pToolBarDlg;

    5. 在CToolBarDialog.cpp里面添加:

    #include "stdafx.h"
    #include "SingleDoc.h"
    #include "ToolBarDialog.h"


    // CToolBarDialog dialog
    CToolBarDialog* g_pToolBarDlg = 0;

    static CToolBarDialog g_sToolBarDlg;

    IMPLEMENT_DYNAMIC(CToolBarDialog, CDialog)

    CToolBarDialog::CToolBarDialog(CWnd* pParent /*=NULL*/)
    : CDialog(CToolBarDialog::IDD, pParent)
    {
    g_pToolBarDlg = this;
    }

    其中staticCToolBarDialog g_sToolBarDlg;这句话是为了能在程序入口点函数执行之前构造该对话框,也即执行对话框的构造函数,为g_pToolBarDlg赋值。

    6. MainFram.cpp的int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)函数里面添加:

        g_pToolBarDlg->Create(CToolBarDialog::IDD, this);
    g_pToolBarDlg->ShowWindow(SW_SHOW);

    over!

    另外添加2个事件:

    右键单击对话框资源---properties---messsages添加lbuttondbclick和nclbuttonclick这2个事件。

        // 双击对话框的客户区时响应
    afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
    // 双击对话框标题时相应
    afx_msg void OnNcLButtonDblClk(UINT nHitTest, CPoint point);



    添加子对话框:

    1. 资源里面insert dialog。

    2. 右键点击对话框资源,选择:Add Class。

    3. 添加了CChildDialog.h, CToolBarDialog.cpp两个文件。

    4. 为Doc类添加一个类成员变量:CChildDialog m_childDlg;

    5. 跟上面的方法类似为doc类添加全局变量指针:g_pDocPointer;

    6. MainFram.cpp的int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)函数里面添加:

        g_pDocPointer->m_childDlg1.Create(CChildDialog1::IDD, g_pToolBarDlg);
    g_pDocPointer->m_childDlg1.ShowWindow(SW_SHOWNORMAL);





  • 相关阅读:
    TCP/IP Checksum 吐槽
    RHEL安装时加载第三方raid驱动
    RHEL Channel Bonding
    关于case语句中声明变量并初始化的注意事项
    Allocators与Criterion的相同点及区别
    BitSet构造函数的两种特例
    Bitset<>用于unordered container时的默认hash函数
    C++ Stream
    C++Exception知识整理
    C++String知识整理
  • 原文地址:https://www.cnblogs.com/kex1n/p/2381460.html
Copyright © 2011-2022 走看看