#include <windows.h>
#include <shlobj.h>
#pragma comment( lib, "shell32.lib")
void GetDesktopFilePath(char* returnpath,char *path)
{// TCHAR MyDir[_MAX_PATH];
// SHGetSpecialFolderPath(this->GetSafeHwnd(),MyDir,CSIDL_APPDATA,0);
// char str[30]={0};
// unsigned long size=30;
// GetUserName(str,&size);
// sprintf(returnpath,"C:\\Documents and Settings\\%s\\桌面\\%s",str,path);
char m_lpszDefaultDir[MAX_PATH];
char szDocument[MAX_PATH]={0};
memset(m_lpszDefaultDir,0,_MAX_PATH);
LPITEMIDLIST pidl=NULL;
SHGetSpecialFolderLocation(NULL, CSIDL_DESKTOP, &pidl);
if (pidl && SHGetPathFromIDList(pidl, szDocument))
{
GetShortPathName(szDocument,m_lpszDefaultDir,_MAX_PATH);
}
sprintf(returnpath,"%s\\%s",szDocument,path);
}
本文介绍了一个C++函数,用于获取Windows系统的桌面文件夹路径,并允许指定返回路径中的额外文件名或子目录。此方法利用了Windows API中的SHGetSpecialFolderLocation和SHGetPathFromIDList函数。
876

被折叠的 条评论
为什么被折叠?



