//Test.h
#include <afxwin.h>
class CMyApp:public CWinApp{
public:
virtual BOOL InitInstance();
};
class CMainWindow:public CFrameWnd{
public:
CMainWindow();
protected:
afx_msg void OnPaint();
DECLARE_MESSAGE_MAP()
};
//Test.cpp
#include "Hello.h"
CMyApp myApp;
BOOL CMyApp::InitInstance(){
m_pMainWnd=new CMainWindow;
m_pMainWnd->ShowWindow(m_nCmdShow);
m_pMainWnd->UpdateWindow();
return TRUE;
}
BEGIN_MESSAGE_MAP(CMainWindow,CFrameWnd)
ON_WM_PAINT()
END_MESSAGE_MAP()
CMainWindow::CMainWindow(){
Create(NULL,_T("The Hello Application"));
};
void CMainWindow::OnPaint(){
CPaintDC dc(this);
CRect rect;
GetClientRect(&rect);
dc.DrawText(_T("Hello,MFC"),-1,&rect,DT_SINGLELINE | DT_CENTER | DT_VCENTER);
}
CWinApp类表示主程序类,MFC应用程序的核心就是基于CWinApp类的应用程序对象
CFrameWnd类表示主框架类
如果采用C++的虚拟函数来支持动态约束,会导致消耗内存,效率低下,所以采用消息映射机制,是一种解决消息处理函数的动态约束问题
原文:https://www.cnblogs.com/k5bg/p/11103655.html