在Win32 Application 环境下实现MFC窗口的创建

// 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;
}

转载于:https://www.cnblogs.com/xiaoweiwangwang/p/4079521.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值