MFC简单程序宏展开

本文介绍了一个使用MFC框架创建简单应用程序的过程,包括应用程序初始化、窗口创建、消息映射及响应处理。展示了如何定义窗口类,实现绘图和鼠标左键按下事件的处理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#include <afxwin.h>

class CMyApp :public CWinApp {
public:
	BOOL InitInstance();
};
class CMyWnd :public CFrameWnd {
public:
	CMyWnd();
protected:
	afx_msg void OnPaint();
	afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
	DECLARE_MESSAGE_MAP()
	//protected: static const AFX_MSGMAP* __stdcall GetThisMessageMap(); virtual const AFX_MSGMAP* GetMessageMap() const;
};

BEGIN_MESSAGE_MAP(CMyWnd, CFrameWnd)
	ON_WM_PAINT()
	ON_WM_LBUTTONDOWN()
END_MESSAGE_MAP()
/*
__pragma(warning( push )) __pragma(warning( disable : 4867 )) const AFX_MSGMAP* CMyWnd::GetMessageMap() const { return GetThisMessageMap(); } const AFX_MSGMAP* __stdcall CMyWnd::GetThisMessageMap() { typedef CMyWnd ThisClass; typedef CFrameWnd TheBaseClass; __pragma(warning(push)) __pragma(warning(disable: 4640)) static const AFX_MSGMAP_ENTRY _messageEntries[] = {
	{ 0x000F, 0, 0, 0, AfxSig_vv, (AFX_PMSG)(AFX_PMSGW) (static_cast< void ( CWnd::*)(void) > ( &ThisClass :: OnPaint)) },
{0, 0, 0, 0, AfxSig_end, (AFX_PMSG)0 } }; __pragma(warning(pop)) static const AFX_MSGMAP messageMap = { &TheBaseClass::GetThisMessageMap, &_messageEntries[0] }; return &messageMap; } __pragma(warning( pop ))
*/

/*//优化后代码
const AFX_MSGMAP* CMyWnd::GetMessageMap() const { return GetThisMessageMap(); }
const AFX_MSGMAP* CMyWnd::GetThisMessageMap() { typedef CMyWnd ThisClass; typedef CFrameWnd TheBaseClass; static const AFX_MSGMAP_ENTRY _messageEntries[] = {
	{ 0x000F, 0, 0, 0, AfxSig_vv, (AFX_PMSG)(AFX_PMSGW) (static_cast< void ( CWnd::*)(void) > ( &ThisClass :: OnPaint)) },
{0, 0, 0, 0, AfxSig_end, (AFX_PMSG)0 } }; static const AFX_MSGMAP messageMap = { &TheBaseClass::GetThisMessageMap, &_messageEntries[0] }; return &messageMap; }
*/

BOOL CMyApp::InitInstance() {
	m_pMainWnd = new CMyWnd;
	m_pMainWnd->ShowWindow(m_nCmdShow);
	m_pMainWnd->UpdateWindow();
	return TRUE;
}
CMyWnd::CMyWnd() {
	Create(NULL, _T("MFC主窗口"));
	
}
void CMyWnd::OnPaint() {
	CPaintDC dc(this);
	CRect rc;
	GetClientRect(&rc);
	dc.DrawText(_T("hello,MFC."), rc, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
}
void CMyWnd::OnLButtonDown(UINT nFlags, CPoint point){
	MessageBox(CString(_T("123")));
}
CMyApp theApp;

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值