1 Windows系统获取桌面路径
可使用以下代码获取桌面路径:
#include <iostream>
#include <string>
#include<Windows.h>
#include "shlobj.h"
std::string GetDesktopPath()
{
LPITEMIDLIST pidl;
LPMALLOC pShellMalloc;
char szDir[MAX_PATH];
if (SUCCEEDED(SHGetMalloc(&pShellMalloc)))
{
if (SUCCEEDED(SHGetSpecialFolderLocation(NULL, CSIDL_DESKTOP, &pidl)))
{
SHGetPathFromIDListA(pidl, szDir);
pShellMalloc->Free(pidl);
}
pShellMalloc->Release();
}
return std::string(szDir);
}
int main()
{
std::string desketop_path = GetDesktopPath();
std::cout << "desketop path : " << GetDesktopPath() << std::endl;
return 0;
}
其中,CSIDL_DESKTOP
对应系统中桌面的路径,我们也可以通过SHGetSpecialFolderLocation
函数获取其他的路径。
例如:
- CSIDL_BITBUCKET:回收站
- CSIDL_CONTROLS:控制面板
- CSIDL_DESKTOP:桌面
- CSIDL_DESKTOPDIRECTORY
- CSIDL_DRIVES:我的电脑
- CSIDL_PERSONAL:我的文档
- CSIDL_RECENT:最近打开文档
- CSIDL_STARTUP:启动目录
本文作者:StubbornHuang
版权声明:本文为站长原创文章,如果转载请注明原文链接!
原文标题:C++ – Windows系统获取桌面路径
原文链接:https://www.stubbornhuang.com/2586/
发布于:2023年04月07日 13:12:27
修改于:2023年06月21日 16:50:36
当前分类随机文章推荐
- CMake - Windows系统设置CMake代理 阅读515次,点赞0次
- C++11 - 使用std::thread::join()/std::thread::detach()方法需要注意的点 阅读3563次,点赞0次
- C++11/std::thread - 线程管理join/detach 阅读2644次,点赞0次
- GCC/G++中编译优化选项-O -O0 -O1 -O2 -O3 -Os -Ofast -Og -Oz各自的区别和作用 阅读5792次,点赞4次
- C++ - std::numeric_limits
简介与使用,用于获取指定数据类型的最大值与最小值 阅读1034次,点赞0次 - C++/OpenCV - 详解如何一步步将OpenCV的cv::Mat转换成深度学习模型推理所需的输入数据 阅读411次,点赞0次
- C++ – 字节数组byte[]或者unsigned char[]与bool的相互转换 阅读1420次,点赞1次
- C++11/std::thread - 线程的基本用法 阅读3660次,点赞0次
- C++11 - std::shared_ptr初始化的几种方式 阅读7505次,点赞2次
- C++ - 字节数组byte[]或者unsigned char[]与int的相互转换 阅读8510次,点赞2次
全站随机文章推荐
- 资源分享 - Computer Animation - Algorithms and Techniques (Third Edition) 英文高清PDF下载 阅读2752次,点赞1次
- 资源分享 - Mathematical Basics of Motion and Deformation in Computer Graphics , Second Edition 英文PDF下载 阅读965次,点赞0次
- Python - BeautifulSoup的find()和findAll() 阅读3089次,点赞0次
- Pytorch – 使用torch.matmul()替换torch.einsum(‘nkctv,kvw->nctw’,(a,b))算子模式 阅读1390次,点赞0次
- Modern OpenGL从零开始 - 在Visual Studio中配置OpenGL开发环境 阅读2804次,点赞0次
- 资源分享 - Game Programming Algorithms and Techniques - A Platform-Agnostic Approach 英文高清PDF下载 阅读1828次,点赞0次
- OpenCV - 将图片/视频转换为深度学习模型输入格式,BGR通道转RGB,图片归一化,HWC转CHW 阅读5719次,点赞0次
- 资源分享 - OpenGL编程指南(原书第9版)- OpenGL红宝书高清带书签PDF下载 阅读15475次,点赞4次
- 资源分享 - Computer Graphics Programming in OpenGL with C++, Second Edition 英文高清PDF下载 阅读3326次,点赞0次
- Pac - OneDriver/OneNote Pac规则 阅读5611次,点赞3次
评论
169