MFC简单程序宏展开

#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;

猜你喜欢

转载自blog.csdn.net/suifengTYZ/article/details/82532242