标签:
关于得到 pidl (即:PathIDList)
的函数有:
SHGetSpecialFolderLocation(): 获得系统目录的位置
SHGetPathFromIDList (): 将 pidl 转化为文件夹路径
SHBrowseForFolder():
显示浏览文件夹对话框
SHBrowseForFolder()
是一个可以用于获取文件夹路径的Windows API
SHGetDesktopFolder()
函数原型:
下面以在VC中使用为例来获取桌面路径,代码如下: LPITEMIDLIST ppidl; char lpsbuf[255] = {0}; SHGetSpecialFolderLocation(NULL,CSIDL_DESKTOP, &ppidl); SHGetPathFromIDList(ppidl, lpsbuf); MessageBox(lpsbuf);
示例代码VC++ LPITEMIDLIST pidl; LPMALLOC pShellMalloc; char szDir[200] = {0}; if(SUCCEEDED(SHGetMalloc(&pShellMalloc))) { if(SUCCEEDED(SHGetSpecialFolderLocation(NULL,CSIDL_DESKTOP, &pidl))) { <span style="white-space:pre"> </span>//如果成功返回true SHGetPathFromIDList(pidl, szDir); pShellMalloc->Free(pidl); } pShellMalloc->Release(); } ::MessageBox (NULL, szDir, "Path", MB_OK);
void CDlgTestDlg::OnBnClickedOk() { LPITEMIDLIST pidl; TCHAR szPath [MAX_PATH]; if(SUCCEEDED( SHGetSpecialFolderLocation ( NULL, CSIDL_FAVORITES, &pidl ))) { if ( SHGetPathFromIDList ( pidl, szPath )) { CString sDisplayName; SHFILEINFO sfi; ZeroMemory(&sfi,sizeof(sfi)); UINT uFlags = SHGFI_PIDL | SHGFI_DISPLAYNAME; SHGetFileInfo((LPCTSTR)pidl, 0, &sfi, sizeof(SHFILEINFO), uFlags); sDisplayName = sfi.szDisplayName; CString szDisplay; szDisplay.Format(_T(" %s /n /n %s"),szPath, sDisplayName); GetDlgItem(IDC_STATIC)->SetWindowText(szDisplay); CoTaskMemFree(pidl); //free the resource } } }
SPDL: SHGetSpecialFolderLocation 获得系统目录的位置
标签:
原文地址:http://blog.csdn.net/jiangqin115/article/details/46678831