// Win32下MFC.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
class CMyFrameWnd:public CFrameWnd
{
//类内添加声明宏
DECLARE_MESSAGE_MAP()
public: //标准实现类内声明消息函数
afx_msg int OnCreate(LPCREATESTRUCT cs);
afx_msg void OnPaint();
/* 非标准的实现类内声明消息函数
//类内声明消息函数
public:
LRESULT OnCreate(WPARAM wParam,LPARAM lParam);
LRESULT OnPaint(WPARAM wParam,LPARAM lParam);
*/
};
//类外
BEGIN_MESSAGE_MAP(CMyFrameWnd,CFrameWnd)//(本类和基类)
//在BEGIN与END之间添加消息
ON_WM_CREATE()
ON_WM_PAINT()
END_MESSAGE_MAP()
//标准形式实现消息函数类外的定义
int CMyFrameWnd::OnCreate(LPCREATESTRUCT cs)
{
AfxMessageBox("即将创建一个窗口!");
return 0;
}
void CMyFrameWnd::OnPaint()
{
PAINTSTRUCT ps={0};
HDC hDc=::BeginPaint(this->m_hWnd,&ps);
::TextOut(hDc,200,200,"Hello",5);
::EndPaint (m_hWnd,&ps);
}
/* 非标准的实现类外函数的定义
//在类外实现窗口创建函数功能
LRESULT CMyFrameWnd::OnCreate (WPARAM wParam,LPARAM lParam)
{
AfxMessageBox("即将创建一个窗口!");
return 0;
}
//类外实现绘图功能
LRESULT CMyFrameWnd::OnPaint (WPARAM wParam,LPARAM lParam)
{
PAINTSTRUCT cs={0};
HDC hDc=::BeginPaint(this->m_hWnd,&cs);
::TextOut(hDc,200,200,"hello",5);
::EndPaint(m_hWnd,&cs);
return 0;
}
*/
//应用程序类
class CMyWinApp:public CWinApp
{
public:
CMyWinApp();
virtual BOOL InitInstance();
};
CMyWinApp theApp;
CMyWinApp::CMyWinApp()
{
}
//重新添加虚函数功能
BOOL CMyWinApp::InitInstance()
{
CMyFrameWnd *pFrame=new CMyFrameWnd();
pFrame->Create(NULL,"MFCCmd");
m_pMainWnd=pFrame;
pFrame->ShowWindow(SW_SHOW);
pFrame->UpdateWindow();
return TRUE;
}