C++基於對話方塊的程式的架構執行個體_C 語言

來源:互聯網
上載者:User

本文執行個體講述了C++基於對話方塊的程式的架構。分享給大家供大家參考。具體如下:

resource.cpp源檔案如下:

複製代碼 代碼如下:
#include "resource.h" 
 
CMyApp theApp; 
 
BOOL CMyApp::InitInstance() 
{ 
    CMainDialog dlg; 
    m_pMainWnd = &dlg;   //給m_pMainWnd 主視窗 
    dlg.DoModal(); 
    return FALSE; //不進入訊息迴圈 
} 
 
 
BEGIN_MESSAGE_MAP(CMainDialog, CDialog) 
ON_BN_CLICKED(IDC_STOP, OnStop) 
ON_MESSAGE(WM_CUTTERSTART, OnCutterStart) //自訂訊息 
END_MESSAGE_MAP() 
//CMainDialog 
CMainDialog::CMainDialog(CWnd* pParentWnd):CDialog(IDD_MAIN, pParentWnd) 
{ 
 
} 
BOOL CMainDialog::OnInitDialog( ) 
{ 
    CDialog::OnInitDialog(); 
    return TRUE; 
} 
void CMainDialog::OnStop() 
{ 
    MessageBox("OnStop"); 
} 
long CMainDialog::OnCutterStart(WPARAM wParam, LPARAM lParam)   //處理自訂訊息 
{ 
    MessageBox("OnCutterStart"); 
    return 0; 
}

resource.h標頭檔如下:

複製代碼 代碼如下:
#include <afxwin.h> 
#define  WM_CUTTERSTART WM_USER+100 
//CMyApp 
class CMyApp:public CWinApp 
{ 
public: 
    BOOL InitInstance(); 
}; 
 
//CMyDialog 
class CMainDialog:public CDialog 
{ 
public: 
    CMainDialog(CWnd* pParentWnd = NULL); 
 
protected: 
    virtual BOOL OnInitDialog( ); 
    afx_msg void OnStop(); 
    afx_msg long OnCutterStart(WPARAM wParam, LPARAM lParam);  //處理自訂訊息的聲明 
 
    DECLARE_MESSAGE_MAP() 
};

希望本文所述對大家的C++程式設計有所協助。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.