头文件hello.h
#pragma once
#include <afxwin.h>
class CMyApp :public CWinApp
{
BOOL InitInstance();
};
class CMainWnd :public CFrameWnd
{
public:
CMainWnd();
protected:
afx_msg void OnPaint();
DECLARE_MESSAGE_MAP()
};
实现文件hello.cpp
#include <afxwin.h>
#include "Hello.h"
CMyApp myApp;
BOOL CMyApp::InitInstance()
{
m_pMainWnd = new CMainWnd;
m_pMainWnd->ShowWindow(m_nCmdShow);
m_pMainWnd->UpdateWindow();
return TRUE;
}
BEGIN_MESSAGE_MAP(CMainWnd,CFrameWnd)
ON_WM_PAINT()
END_MESSAGE_MAP()
CMainWnd::CMainWnd()
{
Create(NULL, _T("Hello, MFC"));
}
void CMainWnd::OnPaint()
{
CPaintDC dc(this);
CRect rect;
GetClientRect(&rect);
dc.DrawText("Hello World", &rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
}