用VS2017创建EXE带MFC类库方法
1. File --> New --> Project
2. Windows桌面向导
3. 勾选MFC类库
4. 创建成功
如果项目编译出错
1. 项目创建成功后编译报错界面
原因分析:缺少#include <afxwin.h>头文件。
解决方案:在#include "Project1.h"后面添加#include <afxwin.h>,编译通过。
如果上述方法不行,可参考下面解决方法,否则跳过以下内容。
原因分析:对比别人创建成功的项目,发现多了一个#include "framework.h"
解决方案:copy成功项目的framework.h头文件,并#include "framework.h",另外framework.h头文件中引用了targetver.h头文件,因此,将targetver.h头文件也copy过来
2. 编译成功后的界面
3. framework.h
#pragma once #include "targetver.h" #include <stdio.h> #include <tchar.h> #define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // 部分 CString 构造函数将是显式的 #define _AFX_NO_MFC_CONTROLS_IN_DIALOGS // 移除对话框中的 MFC 控件支持 #ifndef VC_EXTRALEAN #define VC_EXTRALEAN // 从 Windows 头文件中排除极少使用的内容 #endif #include <afx.h> #include <afxwin.h> // MFC 核心组件和标准组件 #include <afxext.h> // MFC 扩展 #ifndef _AFX_NO_OLE_SUPPORT #include <afxdtctl.h> // MFC 对 Internet Explorer 4 公共控件的支持 #endif #ifndef _AFX_NO_AFXCMN_SUPPORT #include <afxcmn.h> // MFC 对 Windows 公共控件的支持 #endif // _AFX_NO_AFXCMN_SUPPORT #include <iostream>