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.编译,运行

运行结果

相关推荐
blog_wanghao4 小时前
MFC: 文件加解密(单元测试模块)
c++·单元测试·mfc
火龙映天6 小时前
Android Studio历史版本下载方法
android·ide·android studio
m0_635647486 小时前
Qt找不到windows API报错:error: LNK2019: 无法解析的外部符号 __imp_OpenClipboard
开发语言·c++·ide·qt
獨枭6 小时前
Visual Studio 调试中 PDB 与图像不匹配
ide·visual studio
楼田莉子8 小时前
C++学习之STL学习:string类使用
开发语言·c++·学习·容器·visual studio
love530love9 小时前
与 JetBrains 官方沟通记录(PyCharm 相关问题反馈)
ide·人工智能·windows·笔记·python·pycharm·conda
獨枭10 小时前
CRichEditCtrl 控件实现日志输出
c++·mfc
Tipriest_18 小时前
ubuntu20.04&vscode使用C++20(调整gcc版本&vscode设置)
ide·vscode·c++20·gcc
航Hang*1 天前
C PRIMER PLUS——第13节:高级数据表示
c语言·开发语言·visual studio
水饺编程1 天前
编程技能:字符串函数10,strchr
c语言·c++·windows·mfc