头文件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);
}
本文展示了一个使用MFC框架创建简单窗口程序的例子。通过继承CWinApp和CFrameWnd类,实现了显示“Hello World”的窗口,并重写了OnPaint方法以绘制文本。
6834

被折叠的 条评论
为什么被折叠?



