各位大侠,
vc里面可以选中文件夹的窗口是
什么函数?

解决方案 »

  1.   

    CFileDialog myDlg(参数);
    myDlg.DoModal();
      

  2.   

    CString& CDlldiffApp::BrowseForFolder(
               HWND hWnd, LPCSTR lpszTitle, UINT nFlags)
    {
      // We're going to use the shell to display a 
      // "Choose Directory" dialog box for the user.
      
      CString strResult = "";
      
      LPMALLOC lpMalloc;  // pointer to IMalloc
      if (::SHGetMalloc(&lpMalloc) != NOERROR)
         return strResult; // failed to get allocator  char szDisplayName[_MAX_PATH];
      
      char szBuffer[_MAX_PATH];  BROWSEINFO browseInfo;
      browseInfo.hwndOwner = hWnd;
      // set root at Desktop
      browseInfo.pidlRoot = NULL; 
      browseInfo.pszDisplayName = "monkey";
      browseInfo.lpszTitle = "monkey";   // passed in
      browseInfo.ulFlags = BIF_EDITBOX;   // also passed in
      browseInfo.lpfn = NULL;      // not used
      browseInfo.lParam = 0;      // not used     
      LPITEMIDLIST lpItemIDList;  if ((lpItemIDList = ::SHBrowseForFolder(&browseInfo)) 
           != NULL)
      {
         // Get the path of the selected folder from the
         // item ID list.
    if (::SHGetPathFromIDList(lpItemIDList, szBuffer))
         {
            // At this point, szBuffer contains the path 
            // the user chose.
            if (szBuffer[0] == '\0')
            {
               // SHGetPathFromIDList failed, or
               // SHBrowseForFolder failed.
               //AfxMessageBox(IDP_FAILED_GET_DIRECTORY,
               //   MB_ICONSTOP|MB_OK);
               return strResult;
            }
         
            // We have a path in szBuffer!
            // Return it.
            strResult = szBuffer;
            return strResult;
         }
         else
         {
            // The thing referred to by lpItemIDList 
            // might not have been a file system object.
            // For whatever reason, SHGetPathFromIDList
            // didn't work!
            //AfxMessageBox(IDP_FAILED_GET_DIRECTORY,
            //   MB_ICONSTOP|MB_OK);
            return strResult; // strResult is empty 
         }
      lpMalloc->Free(lpItemIDList);
      lpMalloc->Release();      
       }// If we made it this far, SHBrowseForFolder failed.
    return strResult;
    }
      

  3.   

    CString CYourDialogClass::BrowseForDir(){BROWSEINFO BrowseInfo;LPITEMIDLIST pidlSelectedFolder=NULL;LPCITEMIDLIST pidlRelative=NULL;LPITEMIDLIST pidlItems = NULL;IShellFolder *psfParent=NULL;IShellFolder *psfDesktop=NULL;char buf[MAX_PATH];char pathbuff[MAX_PATH];LPMALLOC pMalloc=NULL;CString result;TCHAR pszDisplayName[MAX_PATH];STRRET strDispName;ULONG uAttr;LPENUMIDLIST ppenum = NULL;HRESULT hr;strcpy(pathbuff,"");strcpy(buf,"");
    result="NONE";BrowseInfo.hwndOwner=this->m_hWnd;BrowseInfo.pidlRoot=NULL;BrowseInfo.pszDisplayName=buf;BrowseInfo.lpszTitle="Please select a folder";BrowseInfo.ulFlags=BIF_BROWSEINCLUDEFILES|BIF_USENEWUI;// BrowseInfo.ulFlags=BIF_USENEWUI;BrowseInfo.lpfn=NULL;BrowseInfo.lParam=0;BrowseInfo.iImage=0;
    CoInitialize(NULL);SHGetMalloc(&pMalloc);
    pidlSelectedFolder = SHBrowseForFolder(&BrowseInfo);if (pidlSelectedFolder){hr = SHBindToParent(pidlSelectedFolder,IID_IShellFolder, (void **)
    &psfParent, &pidlRelative);psfParent->GetDisplayNameOf(pidlRelative, SHGDN_INFOLDER, &strDispName);StrRetToBuf(&strDispName, pidlRelative, pszDisplayName, MAX_PATH);uAttr = SFGAO_FOLDER;psfParent->GetAttributesOf(1, (LPCITEMIDLIST *) &pidlRelative, &uAttr);if(uAttr & SFGAO_FOLDER)SHGetPathFromIDList(pidlSelectedFolder,pathbuff);else if (ReturnFile)SHGetPathFromIDList(pidlSelectedFolder,pathbuff);elseAfxMessageBox("You must select a folder");}else{ //user cancelledresult="CANCELED";pMalloc->Release();return result;}if (strlen(pathbuff) != 0 ){result = pathbuff;pMalloc->Free(pidlSelectedFolder);psfParent->Release();return result;}pMalloc->Release();return result;}
      

  4.   


    void CBackupRestore::OnButtonFindBackup() 
    {
    BROWSEINFO info;
    CString str_Path = "";
    memset(&info, 0, sizeof info);
    info.lpszTitle = "选择将要存放备份文件所在路径";
    LPCITEMIDLIST pidl;
    pidl = SHBrowseForFolder(&info);
    if(pidl != NULL)
    {
    char pszPath[4096];
    if(!SHGetPathFromIDList(pidl, pszPath))
    return;
    if(strlen(pszPath) < 3)
    return;
    str_Path = pszPath;
    }
    }
      

  5.   

    前面加:
    #include "Shlobj.h"
    #pragma comment( lib , "Shell32.lib" )