標籤:ifd TE test 開始 方式 指標 include 修改 this
在非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;}
MFC對話方塊跨檔案調用