MFC對話方塊跨檔案調用

來源:互聯網
上載者:User

標籤: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對話方塊跨檔案調用

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.