C++基于对话框的程序的框架实例
本文实例讲述了C++基于对话框的程序的框架。分享给大家供大家参考。具体如下:
resource.cpp源文件如下:
#include"resource.h" CMyApptheApp; BOOLCMyApp::InitInstance() { CMainDialogdlg; m_pMainWnd=&dlg; //给m_pMainWnd主窗口 dlg.DoModal(); returnFALSE;//不进入消息循环 } 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) { } BOOLCMainDialog::OnInitDialog() { CDialog::OnInitDialog(); returnTRUE; } voidCMainDialog::OnStop() { MessageBox("OnStop"); } longCMainDialog::OnCutterStart(WPARAMwParam,LPARAMlParam) //处理自定义消息 { MessageBox("OnCutterStart"); return0; }
resource.h头文件如下:
#include<afxwin.h> #define WM_CUTTERSTARTWM_USER+100 //CMyApp classCMyApp:publicCWinApp { public: BOOLInitInstance(); }; //CMyDialog classCMainDialog:publicCDialog { public: CMainDialog(CWnd*pParentWnd=NULL); protected: virtualBOOLOnInitDialog(); afx_msgvoidOnStop(); afx_msglongOnCutterStart(WPARAMwParam,LPARAMlParam); //处理自定义消息的声明 DECLARE_MESSAGE_MAP() };
希望本文所述对大家的C++程序设计有所帮助。