版权声明:K5出品,必属精品,欢迎收藏评论 https://blog.csdn.net/a694861283/article/details/87358962
//Hello.h
#pragma once
#include <afxwin.h>
//MFC应用程序的核心就是基于CWinApp类的应用程序对象
//CWinApp提供了消息循环来检索消息并将消息调度给应用程序的窗口
class CMyApp:public CWindApp{
public:
virtual BOOL InitInstance();
};
class CMainWindow:public CFrameWnd{
public:
CMainWindow();
protected:
afx_msg void OnPaint();
DECLEAR_MESSAGE_MAP();
};
//Hello.cpp
#include "Hello.h"
//一个MFC应用程序可以有且仅有一个应用程序对象,该对象必须声明为在全局范围内有效,以便于在程序开始时在//内存中被实例化
CMyApp myApp;
//由全局对象CMyApp->AfxWindMain()->AfxWinInit()->InitApplication()和InitInstance()
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(){
Cretae(NULL,_T("K5"));
}
//初始化后调用Run()执行消息循环并开始向应用程序窗口发送消息
void CMainWindow::OnPaint(){
//仅在OnPaint消息内使用CPaintDC对象,它会隐形调用::EndPaint()来移除消息,不然会一直调用
CPaintDC dc(this);
CRect rect;
GetClientRect(&rect);
dc.DrawText(_T("hello"),-1,&rect,DT_SINGLELINE|DT_CENTER|DT_VCENTER);
}