Afx.h //MFC 基本类框架app
Afxwin.h //MFC 程序框架框架
CwinApp //程序对象函数
CFrame //程序框架this
InitInstance();//初始化函数spa
//消息入口对象
DECLARE_MESSAGE_MAP()(在CFrame中定义)继承
//消息处理开始it
BEGIN_MESSAGE_MAP(CMainWindow,CFrameWnd)io
//绘画class
ON_WM_PAINT()
//消息结束
END_MESSAGE_MAP()
(1) 继承CwinApp 定义绘制窗口函数OnPaint
(2) 继承CFrame 定义初始化函数 Initistance
(3) 实现CwinApp构造函数建立窗口(Create(NULL,title))
(4) 实现OnPaint函数绘制程序GUI
(5) 实现初始化函数Initinstance (将CwinApp保存到m_pMainWind中负责没法运行)
App.h
#ifndef _AFXDLL
#define _AFXDLL
#endif
#include <afx.h>
#include <afxwin.h>
class SelfApp:public CWinApp
{
public :
//初始化函数
virtual BOOL InitInstance();
};
class CMainWindow :public CFrameWnd
{
public:
CMainWindow();
protected:
afx_msg void OnPaint();
//消息入口
DECLARE_MESSAGE_MAP()
};
Appi.cpp
#include "app.h"
SelfApp app;
CMainWindow * mainwnd;
//实现函数及构造函数
BOOL SelfApp::InitInstance()
{
mainwnd = new CMainWindow;
mainwnd->ShowWindow(m_nCmdShow);
mainwnd->UpdateWindow();
m_pMainWnd = mainwnd;
return TRUE;
}
//消息处理开始
BEGIN_MESSAGE_MAP(CMainWindow,CFrameWnd)
//绘画
ON_WM_PAINT()
//消息结束
END_MESSAGE_MAP()
CMainWindow::CMainWindow()
{
//建立窗口
Create(NULL,TEXT("The Application"));
}
void CMainWindow::OnPaint()
{ //绘制笔
CPaintDC dc(this);
CRect rect;
GetClientRect(&rect);
//绘制文本
dc.DrawText(__T("This is MFC application"),-1,&rect,DT_SINGLELINE|DT_CENTER|DT_VCENTER);
}