16,471
社区成员
发帖
与我相关
我的任务
分享
BROWSEINFO bi;
bi.hwndOwner=m_hWnd;
bi.pidlRoot=NULL;
bi.pszDisplayName=NULL;
bi.lpszTitle=NULL;
bi.ulFlags=BIF_STATUSTEXT|BIF_USENEWUI|BIF_RETURNONLYFSDIRS;;
bi.lpfn =NULL;
bi.iImage =0;
LPCITEMIDLIST pidl=SHBrowseForFolder(&bi);
if(!pidl)
return;
TCHAR szDisplayName[255];
SHGetPathFromIDList(pidl,szDisplayName);
CString str(szDisplayName);
void CTest::SelectDirDlg(char Dir[])
{
BROWSEINFO bi;
ITEMIDLIST *pidl;
bi.hwndOwner = NULL;
bi.pidlRoot = NULL;
bi.pszDisplayName = Dir;
bi.lpszTitle = "选择一个目录";
bi.ulFlags = BIF_RETURNONLYFSDIRS;
bi.lpfn = NULL;
bi.lParam = 0;
bi.iImage = 0;
pidl = SHBrowseForFolder( &bi ); /* Display "Select Folder" dialog box, Get the folder name and convert it into a ITEMLIST data structure. */
if ( pidl == NULL )
Dir[0] = 0;
if (!SHGetPathFromIDList( pidl, Dir )) /* Retrieve folder name from ITEMLIST structure. */
Dir[0] = 0;
}
void CDlgBackSet::OnButtonFolder()
{//选择路径
// TODO: Add your control notification handler code here
m_sFolder=BrowseForFolder(this->m_hWnd);
SetDlgItemText(IDC_EDIT_FOLDER,m_sFolder);
}
CString CDlgBackSet::BrowseForFolder(HWND hWnd)
{//选择保存备份路径函数
TCHAR szTitle[] = _T("选择备份路径");
TCHAR szDisplayName[MAX_PATH] = _T("");
TCHAR szPath[MAX_PATH] = _T("");
BROWSEINFO bi;
bi.hwndOwner = hWnd;
bi.pidlRoot = NULL;
bi.lpszTitle = szTitle;
bi.pszDisplayName = szDisplayName;
bi.ulFlags = BIF_RETURNONLYFSDIRS;
bi.lpfn = NULL;
bi.lParam = 0;
LPITEMIDLIST pItemIDList = SHBrowseForFolder( &bi );
if( pItemIDList )
{
SHGetPathFromIDList(pItemIDList,szPath) ;
IMalloc *pMalloc;
if( SHGetMalloc( &pMalloc ) != NOERROR )
{
TRACE( "Failed to get pointer to shells task allocator" ) ;
return szPath;
}
pMalloc->Free( pItemIDList );
if( pMalloc )
pMalloc->Release();
}
return szPath;
}