BOOL OpenDirBroswer(LPSTR sPath,CWnd *pParent)
{
BOOL bReturn=FALSE;
BROWSEINFO bi;
TCHAR szDisplayName[MAX_PATH];
LPITEMIDLIST pidl;
LPMALLOC pMalloc = NULL; ZeroMemory(&bi, sizeof(bi));
bi.hwndOwner = pParent->m_hWnd;
bi.pszDisplayName = szDisplayName;
bi.lpszTitle = TEXT("Save to:");
bi.ulFlags = BIF_RETURNONLYFSDIRS;
pidl = SHBrowseForFolder(&bi);
if (pidl)
{
SHGetPathFromIDList(pidl, sPath); // set the directory name.
bReturn=TRUE;
}
else
strcpy(sPath,"");
// free the pidl using the shell's task allocator.
if (SHGetMalloc(&pMalloc) == NOERROR)
pMalloc->Free((void *)pidl); return bReturn;
}void CTestDlg::OnButton1()
{
char sReturnPath[127];
if (OpenDirBroswer(sReturnPath,this))
{
MessageBox(sReturnPath,"",MB_OK);
}
}
{
BOOL bReturn=FALSE;
BROWSEINFO bi;
TCHAR szDisplayName[MAX_PATH];
LPITEMIDLIST pidl;
LPMALLOC pMalloc = NULL; ZeroMemory(&bi, sizeof(bi));
bi.hwndOwner = pParent->m_hWnd;
bi.pszDisplayName = szDisplayName;
bi.lpszTitle = TEXT("Save to:");
bi.ulFlags = BIF_RETURNONLYFSDIRS;
pidl = SHBrowseForFolder(&bi);
if (pidl)
{
SHGetPathFromIDList(pidl, sPath); // set the directory name.
bReturn=TRUE;
}
else
strcpy(sPath,"");
// free the pidl using the shell's task allocator.
if (SHGetMalloc(&pMalloc) == NOERROR)
pMalloc->Free((void *)pidl); return bReturn;
}void CTestDlg::OnButton1()
{
char sReturnPath[127];
if (OpenDirBroswer(sReturnPath,this))
{
MessageBox(sReturnPath,"",MB_OK);
}
}
LPITEMIDLIST m_SelectedDir; GetCurrentDirectory(_MAX_PATH, szSavePath);
BROWSEINFO info;
info.hwndOwner = NULL;
info.pidlRoot = NULL;
info.pszDisplayName =NULL;
info.lpszTitle = "选择系统数据的存储目录";
info.ulFlags = BIF_RETURNONLYFSDIRS;
info.lpfn = NULL;
info.lParam = NULL;
info.iImage = NULL;
m_SelectedDir = SHBrowseForFolder(&info);
CString path;
SHGetPathFromIDList(m_SelectedDir,szSavePath);
if(m_SelectedDir!=NULL){
SetDlgItemText(IDC_DATAPATH,szSavePath);
}