How To Get System Folder Path(C:Windows C:Program Files) in Windows using C++?(如何使用 C++ 在 Windows 中获取系统文件夹路径(C:Windows C:Program Files)?)
问题描述
我正在用 C++ MFC 编程,
I am programming in c++ MFC,
我想获取C:windows"c:program files"文件夹路径.
I want to get "C:windows" "c:program files" folder path.
有时用户可能会在其他文件夹中设置窗口,例如 c:windows0.
是否有任何 API 来获取窗口的绝对路径和程序文件路径?
Sometimes user may setup windows in other folder such as c:windows0.
Is there any API to get absolute path of the windows and program files path?
非常感谢!
推荐答案
使用 Win32 API>
Using Win32 API>
对于 Windows 文件夹:
For the Windows folder:
TCHAR windir[MAX_PATH];
GetWindowsDirectory(windir, MAX_PATH);
对于程序文件:
TCHAR pf[MAX_PATH];
SHGetSpecialFolderPath(
0,
pf,
CSIDL_PROGRAM_FILES,
FALSE );
其中 MAX_PATH
来自 Windows 标头,将保证缓冲区足够长以容纳最长(非 UNC)路径.
Where MAX_PATH
comes from the Windows headers and will guarantee the buffer is long enough for the longest (non-UNC) path.
另外,请注意 SHGetSpecialFolderPath
可用于检索其他特殊"文件夹,包括 Windows 文件夹,只需将第三个参数替换为此 列表.
Also, note that SHGetSpecialFolderPath
can be used to retrieve other "special" folder including the Windows folder just by replacing the third parameter to any from this list.
这篇关于如何使用 C++ 在 Windows 中获取系统文件夹路径(C:Windows C:Program Files)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使用 C++ 在 Windows 中获取系统文件夹路径(C:Windows C:Program Files)?


基础教程推荐
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 我有静态或动态 boost 库吗? 2021-01-01
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 常量变量在标题中不起作用 2021-01-01
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 这个宏可以转换成函数吗? 2022-01-01