WINVER 和 _WIN32_WINNT

本文介绍了在Visual C++中针对不同Windows版本所需的宏定义,包括WINVER、_WIN32_WINNT等,并提供了针对各版本Windows及Internet Explorer的具体宏定义值。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

WINVER 和 _WIN32_WINNT 请在WINDOWS.H前定义

从 Visual C++ 2008 开始,Visual C++ 不支持面向 Windows 95、Windows 98、Windows ME 或 Windows NT。
如果您的 WINVER 或 _WIN32_WINNT 宏被指定到这些 Windows 版本之一,则需要修改宏。当升级从 Visual C++
的以前版本创建的项目时,如果将 WINVER 或 _WIN32_WINNT 宏指定到不再受支持的 Windows 版本,可能会看到
与这些宏相关的编译错误。

若要修改宏,请在头文件中添加以下行:
#define WINVER 0x0500
#define _WIN32_WINNT 0x0500

 


=================================== =

Minimum system required                 Macros to define
 Win7                                                      0x601

Windows Server 2008                      _WIN32_WINNT>=0x0600               WINVER>=0x0600
Windows Vista                            _WIN32_WINNT>=0x0600               WINVER>=0x0600
Windows Server 2003                      _WIN32_WINNT>=0x0502               WINVER>=0x0502
Windows XP                               _WIN32_WINNT>=0x0501               WINVER>=0x0501
Windows 2000                             _WIN32_WINNT>=0x0500               WINVER>=0x0500
Windows NT 4.0                           _WIN32_WINNT>=0x0400               WINVER>=0x0400
 Windows Me                               _WIN32_WINDOWS=0x0500     WINVER>=0x0500
Windows 98                               _WIN32_WINDOWS>=0x0410           WINVER>=0x0410
Windows 95                               _WIN32_WINDOWS>=0x0400             WINVER>=0x0400

Windows   Me                                    _WIN32_WINDOWS=0x0490    

=======================================
Internet Explorer 7.0                         _WIN32_IE>=0x0700
Internet Explorer 6.0 SP2                  _WIN32_IE>=0x0603
Internet Explorer 6.0 SP1                 _WIN32_IE>=0x0601 
Internet   Explorer   6.0                       _WIN32_IE>=0x0600    
Internet   Explorer   5.01,   5.5               _WIN32_IE>=0x0501    
Internet   Explorer   5.0,   5.0a,   5.0b       _WIN32_IE>=0x0500    
Internet   Explorer   4.01                      _WIN32_IE>=0x0401    
Internet   Explorer   4.0                       _WIN32_IE>=0x0400    
Internet   Explorer   3.0,   3.01,   3.02       _WIN32_IE>=0x0300

Internet Explorer 5.5                           _WIN32_IE>=0x0550
Internet Explorer 5.01                        _WIN32_IE>=0x0501


#ifndef WINVER  // 指定要求的最低平台是 Windows Vista。
#define WINVER 0x0600    // 将此值更改为相应的值,以适用于 Windows 的其他版本。
#endif
#ifndef _WIN32_WINNT   // 指定要求的最低平台是 Windows Vista。
#define _WIN32_WINNT 0x0600     // 将此值更改为相应的值,以适用于 Windows 的其他版本。
#endif
//PS:0x0500 表示Windows 2000,0x0501为Windows XP,
0x0502为Windows Server 2003,0x0600 为 Windows Vista。

=====================================
NTDDI_VERSION

Windows Server 2008                      NTDDI_VERSION >= NTDDI_LONGHORN
Windows Vista                                NTDDI_VERSION >= NTDDI_VISTA
Windows Server 2003 SP1               NTDDI_VERSION >= NTDDI_WS03SP1
Windows Server 2003                       NTDDI_VERSION >= NTDDI_WS03
Windows XP SP2                           NTDDI_VERSION >= NTDDI_WINXPSP2
Windows XP SP1                           NTDDI_VERSION >= NTDDI_WINXPSP1
Windows XP                                    NTDDI_VERSION >= NTDDI_WINXP
Windows 2000 SP4                        NTDDI_VERSION >= NTDDI_WIN2KSP4
Windows 2000 SP3                        NTDDI_VERSION >= NTDDI_WIN2KSP3
Windows 2000 SP2                        NTDDI_VERSION >= NTDDI_WIN2KSP2
Windows 2000 SP1                        NTDDI_VERSION >= NTDDI_WIN2KSP1
Windows 2000                                 NTDDI_VERSION >= NTDDI_WIN2K

=============Shell and Common Controls Versions=======
Version   DLL    Distribution  Platform
4.0    All    Microsoft Windows 95/Microsoft Windows NT 4.0.
4.7    All    Microsoft Internet Explorer 3.x.
4.71    All    Internet Explorer 4.0. See note 2.
4.72    All    Internet Explorer 4.01 and Windows 98. See note 2.
5.0    Shlwapi.dll  Internet Explorer 5. See note 3.
6.0    Shlwapi.dll  Internet Explorer 6 and Windows XP.
5.0    Shell32.dll   Windows 2000 and Windows Millennium Edition (Windows Me). See note 3.
6.0    Shell32.dll  Windows XP.
5.8    Comctl32.dll  Internet Explorer 5. See note 3.
5.81    Comctl32.dll  Windows 2000 and Windows Me. See note 3.
6.0    Comctl32.dll  Windows XP. See note 4.

#ifndef _SYSTEM_DETECTOR_H_ #define _SYSTEM_DETECTOR_H_ #ifdef _WIN32 //#ifndef _WIN32_WINNT_WIN7 //#define _WIN32_WINNT_WIN7 0x0601 //#endif // !_WIN32_WINNT_WIN7 // 检查编译环境SDK是否支持 //#if (_WIN32_WINNT < _WIN32_WINNT_WIN7) //#error "This application requires Windows SDK 7.0 or higher. Please update your Windows SDK." //#error "此应用程序需要 Windows SDK 7.0 或更高版本进行编译." //#endif #define _CRT_SECURE_NO_WARNINGS #define NO_WARN_MBCS_MFC_DEPRECATION #include <SDKDDKVer.h> #include <afxwin.h> //#include <versionhelpers.h> namespace D2DRENDER { // 枚举操作系统平台类型 enum class OSPlatform { Windows7, Windows8, Windows8_1, Windows10, Windows11, Unknown }; // 系统检测类 class CSystemDetector { public: CSystemDetector(); OSPlatform m_OSPlatform; int m_nCurrentBuild; }; extern CSystemDetector g_SystemDetector; //以下函数都是读取, 不用加锁, 线程安全 //判断是Windows 11 bool IsWin11(); // 判断是Windows 10 bool IsWin10(); // 判断是Windows 8.1 bool IsWin8_1(); // 判断是否Windows 8 bool IsWin8(); // 判断是否Windows 7 bool IsWin7(); // 判断是否win8.1 或以上系统 bool IsWin8_1orGreater(); } #endif // !_WIN32 #endif // !_SYSTEM_DETECTOR_H_ #include "SystemDetector.h" #pragma comment(linker, "/DELAYLOAD:dcomp.dll")//延迟加载dcomp.dll, 运行时才加载,配合LoadLibrary就能知道当前系统有没有dcomp.dll了 D2DRENDER::CSystemDetector g_SystemDetector; D2DRENDER::CSystemDetector::CSystemDetector() :m_OSPlatform(OSPlatform::Unknown), m_nCurrentBuild(0) { // 检测当前操作系统并返回平台类型 HKEY hKey; LONG lResult = RegOpenKeyEx( HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", 0, KEY_READ, &hKey); if (lResult == ERROR_SUCCESS) { DWORD dwType; DWORD dwSize = 16; char szCurrentBuild[16] = { 0 }; RegQueryValueEx(hKey, "CurrentBuild", NULL, &dwType, (LPBYTE)szCurrentBuild, &dwSize); RegCloseKey(hKey); m_nCurrentBuild = atoi(szCurrentBuild); } if (m_nCurrentBuild >= 7600 && m_nCurrentBuild < 9200) { m_OSPlatform = OSPlatform::Windows7; } else if (m_nCurrentBuild >= 9200 && m_nCurrentBuild < 9600) { m_OSPlatform = OSPlatform::Windows8; } else if (m_nCurrentBuild >= 9600 && m_nCurrentBuild < 10240) { m_OSPlatform = OSPlatform::Windows8_1; } else if (m_nCurrentBuild >= 10240 && m_nCurrentBuild < 22000) { m_OSPlatform = OSPlatform::Windows10; } else if (m_nCurrentBuild >= 22000) { m_OSPlatform = OSPlatform::Windows11; } else { m_OSPlatform = OSPlatform::Unknown;//win7 以下都是未知系统 } } //判断是Windows 11 bool D2DRENDER::IsWin11() { return g_SystemDetector.m_OSPlatform == OSPlatform::Windows11; } // 判断是Windows 10 bool D2DRENDER::IsWin10() { return g_SystemDetector.m_OSPlatform == OSPlatform::Windows10; } // 判断是Windows 8.1 bool D2DRENDER::IsWin8_1() { return g_SystemDetector.m_OSPlatform == OSPlatform::Windows8_1; } // 判断是否Windows 8 bool D2DRENDER::IsWin8() { return g_SystemDetector.m_OSPlatform == OSPlatform::Windows8; } // 判断是否Windows 7 bool D2DRENDER::IsWin7() { return g_SystemDetector.m_OSPlatform == OSPlatform::Windows7; } // 判断是否win8.1 或以上系统 bool D2DRENDER::IsWin8_1orGreater() { return g_SystemDetector.m_nCurrentBuild >= 9600; }
08-11
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值