C++基于对话框的程序的框架实例
时间:2021-09-28 09:33:52|栏目:C代码|点击: 次
本文实例讲述了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;
}
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()
};
#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++程序设计有所帮助。
上一篇:C语言fgetc和fputc函数用法详解(以字符形式读写文件)
栏 目:C代码
下一篇:C语言实现贪吃蛇小游戏
本文标题:C++基于对话框的程序的框架实例
本文地址:http://www.codeinn.net/misctech/177906.html