visual studio 2022 手工写一个简单的MFC程序

书籍:《Visual C++ 2017从入门到精通》的2.1.2 MFC方式中2.手工写一个简单的MFC程序

环境:visual studio 2022

内容:手工写一个简单的MFC程序

1.文件->新建->项目

2.根据以下步骤选择Windows桌面向导

3.输入项目名,选择保存位置,点击创建。

4.在弹出的WIndows桌面项目中,选择桌面应用程序(.exe),勾选空项目,然后点击确定。

5.创建新文件test.cpp和test.h.

6.修改项目属性,使其支持MFC编程。

7.编写程序内容

test.h的内容如下

cpp 复制代码
#pragma once

#pragma once
#include <sdkddkver.h>
#include <afxwin.h>
#include <afxwinappex.h>
#include <afxframewndex.h>

class CTestApp : public CWinAppEx
{
public:
	virtual BOOL InitInstance();
};

test.cpp的内容如下:

cpp 复制代码
#include "test.h"
CTestApp theApp;

BOOL CTestApp::InitInstance()
{
	CWinAppEx::InitInstance();

	SetRegistryKey(TEXT("Hello MFC app."));

	AfxMessageBox(_T("Hello World, MFD"));

	return TRUE;
}

8.编译,运行

运行结果

相关推荐
不吃凉粉4 小时前
Android Studio USB串口通信
android·ide·android studio
编程乐学5 小时前
安卓非原创--基于Android Studio 实现的天气预报App
android·ide·android studio·课程设计·大作业·天气预报·安卓大作业
非得登录才能看吗?8 小时前
VScode 入门(设置篇)
ide·vscode·编辑器
Costrict11 小时前
解锁新阵地!CoStrict 现已支持 JetBrains 系列 IDE
大数据·ide·人工智能·深度学习·自然语言处理·ai编程·visual studio
AlphaFinance11 小时前
Windows下Vscode连接到WSL的方法
ide·vscode·编辑器
流水线上的指令侠16 小时前
使用C#写微信小程序后端——电商微信小程序
微信小程序·小程序·c#·visual studio
天庭鸡腿哥21 小时前
可能最后一个版本,作者不更新了!
eclipse·maven·lua·visual studio
techdashen1 天前
圆桌讨论:Coding Agent or AI IDE 的现状和未来发展
ide·人工智能
止观止1 天前
如何开发 VSCode 内置扩展:从零开始构建最简扩展
ide·vscode·编辑器
承渊政道1 天前
动态内存管理
c语言·c++·经验分享·c#·visual studio