zoukankan      html  css  js  c++  java
  • C++第四十三篇 -- VS2017创建控制台程序勾选MFC类库编译报错

    用VS2017创建控制台程序带MFC类库方法

    1. File --> New --> Project

    2. Windows桌面向导

    3. 勾选MFC类库

    4. 创建成功

    解决项目编译出错

    1. 项目创建成功后编译报错界面

    原因分析:对比别人创建成功的项目,发现多了一个#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>
    View Code

    4. targetver.h

    #pragma once
    
    // // 包含 SDKDDKVer.h 可定义可用的最高版本的 Windows 平台。
    // 如果希望为之前的 Windows 平台构建应用程序,在包含 SDKDDKVer.h 之前请先包含 WinSDKVer.h 并
    // 将 _WIN32_WINNT 宏设置为想要支持的平台。
    #include <SDKDDKVer.h>
    View Code

    这样就不会编译出错了。

  • 相关阅读:
    Count and Say leetcode
    Find Minimum in Rotated Sorted Array II leetcode
    Find Minimum in Rotated Sorted Array leetcode
    Search in Rotated Sorted Array II leetcode
    search in rotated sorted array leetcode
    Substring with Concatenation of All Words
    Subsets 子集系列问题 leetcode
    Sudoku Solver Backtracking
    Valid Sudoku leetcode
    《如何求解问题》-现代启发式方法
  • 原文地址:https://www.cnblogs.com/smart-zihan/p/13097458.html
Copyright © 2011-2022 走看看