第一个MFC程序及它的运行流程

第一个MFC程序及它的运行流程

步骤

1.创建空项目并配置属性

属性配置如下,在项目属性中改为以下两项。

在这里插入图片描述

2.书写代码

MyApp.h头文件
#pragma once

#define _WIN32_WINNT 0x0502    //不写这个会有警告
#include <afxwin.h>

class MyApp :public CWinApp
{
public:
	virtual BOOL InitInstance();
};

class MyMainWindow :public CFrameWnd
{
public:
	MyMainWindow();			//主窗口
};
MyApp代码
#include "MyApp.h"

BOOL MyApp::InitInstance()
{
	this->m_pMainWnd = new MyMainWindow();
	this->m_pMainWnd->ShowWindow(this->m_nCmdShow);
	this->m_pMainWnd->UpdateWindow();

	return true;
}

MyMainWindow::MyMainWindow()
{
	Create(NULL, TEXT("第一个MFC程序"));
}
helloMFC.cpp
#include "MyApp.h"

MyApp app;

3.使用的继承

最重要的两个MFC类:

CwinApp
CFrameWnd

MyApp继承的CwinApp类,MyMainWindow继承CFrameWnd。

4.MFC程序运行步骤

1.CwinApp中的全局变量定义

2.调用CwinApp构造函数

3.进入Winmain函数(_tWinMain为宏,值为WinMain)

4.(1) 注册窗口类并创建窗口

AfxEndDeferRegisterClass()(相当于SDK里面的RegisterClass()函数)

CFrameWnd::Create()

参考

https://blog.csdn.net/husongchao/article/details/5063786

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值