有呀!!BOOL GetFolder(CString* strSelectedFolder,
   const char* lpszTitle,
   const HWND hwndOwner, 
   const char* strRootFolder, 
   const char* strStartFolder)
{
char pszDisplayName[MAX_PATH];
LPITEMIDLIST lpID;
BROWSEINFOA bi;

bi.hwndOwner = hwndOwner;
if (strRootFolder == NULL){
bi.pidlRoot = NULL;
}else{
   LPITEMIDLIST  pIdl = NULL;
   IShellFolder* pDesktopFolder;
   char          szPath[MAX_PATH];
   OLECHAR       olePath[MAX_PATH];
   ULONG         chEaten;
   ULONG         dwAttributes;    strcpy(szPath, (LPCTSTR)strRootFolder);
   if (SUCCEEDED(SHGetDesktopFolder(&pDesktopFolder)))
   {
   MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, szPath, -1, olePath, MAX_PATH);
   pDesktopFolder->ParseDisplayName(NULL, NULL, olePath, &chEaten, &pIdl, &dwAttributes);
   pDesktopFolder->Release();
   }
   bi.pidlRoot = pIdl;
}
bi.pszDisplayName = pszDisplayName;
bi.lpszTitle = lpszTitle;
bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_STATUSTEXT;
bi.lpfn = NULL;
if (strStartFolder == NULL){
bi.lParam = FALSE;
}else{
strTmpPath.Format("%s", strStartFolder);
bi.lParam = TRUE;
}
bi.iImage = NULL;
lpID = SHBrowseForFolderA(&bi);
if (lpID != NULL){
BOOL b = SHGetPathFromIDList(lpID, pszDisplayName);
if (b == TRUE){
strSelectedFolder->Format("%s",pszDisplayName);
return TRUE;
}
}else{
strSelectedFolder->Empty();
}
return FALSE;
}
usage:
GetFolder(&strFolderPath, "Sample of  getting folder.", this->m_hWnd, NULL, NULL);

解决方案 »

  1.   

    伤心太平洋,您的代码很详细,但是小弟还是有点不明白:
    strSelectedFolder 是不是指取得的路径(包括文件名)? 
    GetFolder(&strFolderPath, "Sample of  getting folder.", this->m_hWnd, NULL, NULL) 的功能具体指什么呢?请详细告之(呵呵,菜鸟嘛).谢谢
      

  2.   

    是,  GetFolder(&保存所选路径的变量, 标题如:请选择存放的路径, 调用这个函数窗口的hwnd, NULL, NULL).....
      

  3.   

              BROWSEINFO bi ={0}; 
              char pszDisplayName[MAX_PATH] ="\0";
              bi.hwndOwner=NULL;
              bi.pszDisplayName = pszDisplayName;
              bi.lpszTitle="请选择目录:";
              bi.ulFlags=BIF_RETURNONLYFSDIRS;
              LPITEMIDLIST lpIL = SHBrowseForFolder(&bi);
              if(lpIL)
              {    
                       SHGetPathFromIDList(lpIL,bi.pszDisplayName);
              }
             
    // bi.pszDisplayName;就是所选择的目录