void CTestOpenDlg::OnBnClickedButton2()
{
// get root path
char bufRoot[MAX_PATH + 1];
strcpy(bufRoot,"C:\\Users");
bufRoot[strlen(bufRoot)] = '\0';
LPITEMIDLIST rootLoation = ParsePidlFromPath(bufRoot);
if ( rootLoation == NULL )
{
return;
}
BROWSEINFO bi;
ZeroMemory( &bi, sizeof( bi ) );
bi.pidlRoot = rootLoation;
// open dialog
LPITEMIDLIST targetLocation = SHBrowseForFolder( &bi );
if ( targetLocation != NULL )
{
TCHAR targetPath[ MAX_PATH ];
SHGetPathFromIDList( targetLocation, targetPath );
MessageBox( targetPath );
}
}
LPITEMIDLIST CTestOpenDlg::ParsePidlFromPath(LPCSTR path)
{
OLECHAR szOleChar[MAX_PATH];
LPSHELLFOLDER IpsfDeskTop;
LPITEMIDLIST lpifq;
ULONG ulEaten, ulAttribs;
HRESULT hres;
SHGetDesktopFolder(&IpsfDeskTop);
MultiByteToWideChar(CP_ACP,MB_PRECOMPOSED,path,-1,szOleChar,sizeof(szOleChar));
hres = IpsfDeskTop ->ParseDisplayName(NULL, NULL, szOleChar, &ulEaten, &lpifq, &ulAttribs);
hres=IpsfDeskTop->Release( );
if(FAILED(hres))
return NULL;
return lpifq;
}
MFC 打开指定文件夹对话框
最新推荐文章于 2024-06-14 21:16:48 发布