CFileDialog不能选择目录
下面的代码可以进行目录选择
CString strFilePath;
TCHAR pszBuffer[_MAX_PATH];
BROWSEINFO bi; LPITEMIDLIST pidl;
bi.hwndOwner = NULL;
bi.pidlRoot = NULL;
bi.pszDisplayName = pszBuffer;
bi.lpszTitle = _T("目录选择");
bi.ulFlags = BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS;
bi.lpfn = NULL;
bi.lParam = 0;
if((pidl = SHBrowseForFolder(&bi)) != NULL)
{
if(SHGetPathFromIDList(pidl, pszBuffer))
{
CString strTemp(pszBuffer); strFilePath = strTemp;
if (strFilePath.GetLength() <= 1)
{
}
else if (strFilePath.Right(1) != _T("\\"))
strFilePath += _T("\\");
}
}
下面的代码可以进行目录选择
CString strFilePath;
TCHAR pszBuffer[_MAX_PATH];
BROWSEINFO bi; LPITEMIDLIST pidl;
bi.hwndOwner = NULL;
bi.pidlRoot = NULL;
bi.pszDisplayName = pszBuffer;
bi.lpszTitle = _T("目录选择");
bi.ulFlags = BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS;
bi.lpfn = NULL;
bi.lParam = 0;
if((pidl = SHBrowseForFolder(&bi)) != NULL)
{
if(SHGetPathFromIDList(pidl, pszBuffer))
{
CString strTemp(pszBuffer); strFilePath = strTemp;
if (strFilePath.GetLength() <= 1)
{
}
else if (strFilePath.Right(1) != _T("\\"))
strFilePath += _T("\\");
}
}
{
// TODO: Add your control notification handler code here
BROWSEINFO struInfo;
LPCITEMIDLIST pidl;
TCHAR pszPath[MAX_PATH];
TCHAR *pszTitle="请选择程序运行时的起始路径:";
struInfo.hwndOwner=GetSafeHwnd();
struInfo.pszDisplayName=pszPath;
struInfo.pidlRoot=NULL;
struInfo.ulFlags=BIF_DONTGOBELOWDOMAIN | BIF_RETURNONLYFSDIRS;
struInfo.lpfn=NULL;
struInfo.lpszTitle=pszTitle;
struInfo.iImage=0;
pidl=SHBrowseForFolder(&struInfo);
if(pidl==NULL)
return;
if(SHGetPathFromIDList(pidl,pszPath)==FALSE)
return;
m_editRunPath.SetWindowText(pszPath);
}