MFC对话框跨文件调用

    在非doc源文件中调用对话框,先建立好对话框,定义类,变量以及头文件源文件等。因为一开始在建立对话框的时候想着建立独立对话框,就没有设到其他文件中去。

    为了在该对话框中直接引用他cpp中内容,并修改该对话框的头文件和源文件:

(准确来说,不知道这样的有什么好处,如果有想法欢迎留言!谢谢!)

//===========头文件 C_LatticeTransfDlg.h
#include "resource.h"
#include "Mylattice.h"//==需要引用该对话框的文件
class C_LatticeTransfDlg : public CDialogEx
{
    DECLARE_DYNAMIC(C_LatticeTransfDlg)

public:
    C_LatticeTransfDlg(CMyLattice* theLatticePos, CWnd* pParent = NULL);   // 标准构造函数=====此处构造函数添加Mylattice类
    virtual ~C_LatticeTransfDlg();
      #ifdef AFX_DESIGN_TIME              // ==如果是非模态对话框需要去掉该ifdef条件编译语

      enum { IDD = IDD_TransFormDlg };
      #endif

}

.
.
.

//============源文件 C_LatticeTransfDlg.cpp====
#include "stdafx.h"
#include "Liu_Occ.h"
#include "C_LatticeTransf.h"
#include "afxdialogex.h"

C_LatticeTransfDlg::C_LatticeTransfDlg(CMyLattice* theLatticePos, CWnd* pParent /*=NULL*/)//===构造函数
    : CDialogEx(IDD_TransFormDlg, pParent)
    , m_Tx(0)
    , m_Ty(0)
    , m_Tz(0)
    , m_Rx(0)
    , m_Ry(0)
    , m_Rz(0)
    ,iscomplete(false)
{
    myLatticePos = theLatticePos;
}

C_LatticeTransfDlg::~C_LatticeTransfDlg()
{
}
.
.
.

 

在其他文件中调用对话框:

包含对话框头文件后,

#include "C_LatticeTransf.h" 
void
CMyLattice::test5() { C_LatticeTransfDlg *latticeTransfdlg; latticeTransfdlg = new C_LatticeTransfDlg(this); latticeTransfdlg->DoModal(); //==模态对话框打开方式
//latticeTransfdlg->Create(C_LatticeTransfDlg::IDD, NULL);//==如果非模态对话框用下列语句 //latticeTransfdlg->ShowWindow(SW_SHOW); float tx = latticeTransfdlg->Tx; float rx = latticeTransfdlg->Rx; }

 默认的情况如下,可以在其他cpp中引用:

//===头文件

class C_LatticeTransfDlg : public CDialogEx
{
    DECLARE_DYNAMIC(C_LatticeTransfDlg)

public:
    C_LatticeTransfDlg(CWnd* pParent = NULL);   // 标准构造函数
    virtual ~C_LatticeTransfDlg();
// 对话框数据
#ifdef AFX_DESIGN_TIME
    //enum { IDD = IDD_DIALOG4 };
    enum { IDD = IDD_TransFormDlg };
#endif
.
.
.
}


//===源文件
C_LatticeTransfDlg::C_LatticeTransfDlg(CWnd* pParent /*=NULL*/)
    : CDialogEx(IDD_TransFormDlg, pParent)
    , m_Tx(0)
    , m_Ty(0)
    , m_Tz(0)
    , m_Rx(0)
    , m_Ry(0)
    , m_Rz(0)
    ,iscomplete(false)
{
    /*myLatticePos = theLatticePos;*/
}

//==其他源文件
void CMyLattice::test5()
{
    C_LatticeTransfDlg *latticeTransfdlg;
    latticeTransfdlg = new C_LatticeTransfDlg();//==不需要this指针
    latticeTransfdlg->DoModal();

    //latticeTransfdlg->Create(C_LatticeTransfDlg::IDD, NULL);
    //latticeTransfdlg->ShowWindow(SW_SHOW);
    //myAISContext->UpdateCurrentViewer();

    float tx = latticeTransfdlg->Tx;
    float rx = latticeTransfdlg->Rx;
}

 

posted @ 2018-06-26 11:10  JeasonLiu先生  阅读(505)  评论(0编辑  收藏  举报