需要先安装window SDK
**windows.h头文件的位置通常位于[Windows Kits](https://www.baidu.com/s?sa=re_dqa_generate&wd=Windows%20Kits&rsv_pq=826ce39d000a376b&oq=window%20sdk%20%E5%A4%B4%E6%96%87%E4%BB%B6%20windows.h%20%E5%9C%A8%E5%93%AA%E9%87%8C&rsv_t=0eccxBhreAvLKpb4c5Pz5pBO7Vlm7qSMlzSPgleqaZ0/Fn1oqhP66ugGx/iOBuVZt6o&tn=98010089_dg&ie=utf-8)的Include目录下。** 例如,在64位系统上,windows.h的位置可能为:
* **Windows 7 SDK**:`C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Include`
* **Windows 8 SDK**:`C:\Program Files (x86)\Windows Kits\8.0\Include\um`
* **Windows 8.1 SDK**:`C:\Program Files (x86)\Windows Kits\8.1\Include\um`
* **Windows 10 SDK**:`C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\um`
这些路径可能会根据你安装的[Windows Kit](https://www.baidu.com/s?sa=re_dqa_generate&wd=Windows%20Kit&rsv_pq=826ce39d000a376b&oq=window%20sdk%20%E5%A4%B4%E6%96%87%E4%BB%B6%20windows.h%20%E5%9C%A8%E5%93%AA%E9%87%8C&rsv_t=0eccxBhreAvLKpb4c5Pz5pBO7Vlm7qSMlzSPgleqaZ0/Fn1oqhP66ugGx/iOBuVZt6o&tn=98010089_dg&ie=utf-8)版本有所不同。如果你在使用[Visual Studio](https://www.baidu.com/s?sa=re_dqa_generate&wd=Visual%20Studio&rsv_pq=826ce39d000a376b&oq=window%20sdk%20%E5%A4%B4%E6%96%87%E4%BB%B6%20windows.h%20%E5%9C%A8%E5%93%AA%E9%87%8C&rsv_t=0eccxBhreAvLKpb4c5Pz5pBO7Vlm7qSMlzSPgleqaZ0/Fn1oqhP66ugGx/iOBuVZt6o&tn=98010089_dg&ie=utf-8)时遇到找不到windows.h的问题,可以按照以下步骤解决:
1. **检查[项目属性](https://www.baidu.com/s?sa=re_dqa_generate&wd=%E9%A1%B9%E7%9B%AE%E5%B1%9E%E6%80%A7&rsv_pq=826ce39d000a376b&oq=window%20sdk%20%E5%A4%B4%E6%96%87%E4%BB%B6%20windows.h%20%E5%9C%A8%E5%93%AA%E9%87%8C&rsv_t=0eccxBhreAvLKpb4c5Pz5pBO7Vlm7qSMlzSPgleqaZ0/Fn1oqhP66ugGx/iOBuVZt6o&tn=98010089_dg&ie=utf-8)**:右键点击项目 -> 属性 -> 配置属性 -> 常规,确保Windows SDK版本选择的是你已安装的版本。
2. **调整包含目录**:在属性页的VC++目录 -> 包含目录中添加相应的路径,例如 `C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\um`。
通过以上步骤,你应该能够找到并正确引用windows.h头文件。
配置
.vscode\c_cpp_properties.json
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**",
// 这是window sdk路径
"C:/Program Files (x86)/Windows Kits/10/Include/10.0.26100.0/um",
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "D:/huanjing/mingw64/bin/gcc.exe",
"intelliSenseMode": "gcc-x64"
},
{
"name": "C++",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "D:/huanjing/mingw64/bin/g++.exe"
}
],
"version": 4
}
.vscode\launch.json
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) 启动 C++",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/a.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "D:/huanjing/mingw64/bin/gdb.exe",
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "将反汇编风格设置为 Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
]
}
]
}
.vscode\tasks.json
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: gcc.exe 生成活动文件",
"command": "D:/huanjing/mingw64/bin/gcc.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "D:/huanjing/mingw64/bin"
},
"problemMatcher": [
"$gcc"
],
"group": "build",
"detail": "编译器: D:/huanjing/mingw64/bin/gcc.exe"
}
]
}