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("\\");
}
}

解决方案 »

  1.   

    void CSetRunPathPage::OnBrowse() 
    {
    // 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);
    }
      

  2.   

    对了,CFileFind也可以选择目录,不过很弱智,以前见过一个补丁程序,就是这么做的,就是用CFileFind选择一个文件,然后你取这个文件所在目录作为结果,是不是很弱智?