C++基于對話框的程序的框架實例
更新時間:2014年10月15日 16:41:42 投稿:shichen2014
這篇文章主要介紹了C++基于對話框的程序的框架,以實例形式講述了C++對話框程序框架,有助于深入理解基于C++的Windows程序設計,需要的朋友可以參考下
本文實例講述了C++基于對話框的程序的框架。分享給大家供大家參考。具體如下:
resource.cpp源文件如下:
復制代碼 代碼如下:
#include "resource.h"
CMyApp theApp;
BOOL CMyApp::InitInstance()
{
CMainDialog dlg;
m_pMainWnd = &dlg; //給m_pMainWnd 主窗口
dlg.DoModal();
return FALSE; //不進入消息循環(huán)
}
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;
}
CMyApp theApp;
BOOL CMyApp::InitInstance()
{
CMainDialog dlg;
m_pMainWnd = &dlg; //給m_pMainWnd 主窗口
dlg.DoModal();
return FALSE; //不進入消息循環(huán)
}
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()
};
#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++程序設計有所幫助。
相關(guān)文章
C++ 面向?qū)ο蟪绦蛟O計--內(nèi)存分區(qū)詳解
這篇文章主要介紹了剖析C++的面向?qū)ο缶幊趟枷?C++的面向?qū)ο筇匦允瞧鋵語言的重要拓展之處,需要的朋友可以參考下,希望能夠給你帶來幫助2021-08-08C語言中fgetgrent()函數(shù)和fgetpwent()函數(shù)的用法對比
這篇文章主要介紹了C語言中fgetgrent()函數(shù)和fgetpwent()函數(shù)的用法對比,分別用于讀取組格式函數(shù)和讀取密碼格式,需要的朋友可以參考下2015-08-08C語言實現(xiàn)可保存的動態(tài)通訊錄的示例代碼
這篇文章主要為大家詳細介紹了如何利用C語言實現(xiàn)一個簡單的可保存的動態(tài)通訊錄,文中的示例代碼講解詳細,對我們學習C語言有一定幫助,需要的可以參考一下2022-07-07