公共对话框里有吗?

解决方案 »

  1.   

    char Dir[MAX_PATH];
    BROWSEINFO bi; 
    ITEMIDLIST *pidl; 
    //LPITEMIDLIST pidlRoot = NULL;
    //SHGetFolderLocation(NULL, CSIDL_DESKTOP/*nCSIDL*/, NULL, NULL, &pidlRoot);
    bi.hwndOwner = NULL; 
    bi.pidlRoot = NULL; 
    bi.pszDisplayName = Dir; 
    bi.lpszTitle = "选择备份文件路径"; 
    bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_DONTGOBELOWDOMAIN; 
    bi.lpfn = NULL; 
    bi.lParam = 0; 
    bi.iImage = 0; 
    pidl = SHBrowseForFolder( &bi ); 
    /* Display "Select Folder"dia log box, Get the folder name and convert it into a ITEMLIST data structure. */ 
    if ( pidl == NULL ) 
    Dir[0] = 0; 
    /* Retrieve foldernam e from ITEMLIST structure. */ 
    if (!SHGetPathFromIDList( pidl, Dir )) 
    Dir[0] = 0;
    if( Dir[0] != 0 )
    m_sPath = Dir;
      

  2.   

    http://www.vccode.com/file_show.php?id=1521
    下有一个很好的封装类CFileDialogST,CFileDialogST 是用 SDK APIs重新实现的一个用MFC CFileDialog类。这个类最有价值的特性是可以显示新的Windows 2000风格的打开/保存 通用对话框。
    CFileDialogST还包含一个使用通用对话框******选择文件夹的函数******。
      

  3.   

    char str[80];
    BROWSEINFO bi;
    ZeroMemory(&bi,sizeof(BROWSEINFO));
    LPITEMIDLIST pidl = SHBrowseForFolder(&bi);
    SHGetPathFromIDList(pidl, str);
    AfxMessageBox(str);
      

  4.   

    int __stdcall BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData)
    {
    if(uMsg == BFFM_INITIALIZED)
    {
    LPCTSTR lpInitDir = (LPCTSTR)lpData;
    ::SendMessage(hwnd, BFFM_SETSELECTION, TRUE, 
    reinterpret_cast<long>(lpInitDir));
    }
    else if(uMsg == BFFM_SELCHANGED)
    {
    }

    return 0;
    }CString T_SelectPath(LPCTSTR lpszTitle, LPCTSTR lpInitDir, HWND hWnd)
    {
    CString strFilePath;
    TCHAR pszBuffer[_MAX_PATH];
    BROWSEINFO bi;
    LPITEMIDLIST pidl;

    LPMALLOC lpMalloc = NULL;
    SHGetMalloc(&lpMalloc);

    if(hWnd == NULL)
    {
    CWnd *pWnd = AfxGetMainWnd();
    if(pWnd)
    hWnd = pWnd->GetSafeHwnd();
    }
    bi.hwndOwner      = hWnd;
    bi.pidlRoot       = NULL;
    bi.pszDisplayName = pszBuffer;
    bi.lpszTitle      = lpszTitle;
    bi.ulFlags        = BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS;
    bi.lpfn           = BrowseCallbackProc;
    bi.lParam         = (LPARAM)lpInitDir;

    if((pidl = SHBrowseForFolder(&bi)) != NULL)
    {
    if(SHGetPathFromIDList(pidl, pszBuffer))
    {
    strFilePath.Format(pszBuffer);
    if (strFilePath.GetLength() <= 1)
    return _T("");
    if (strFilePath.Right(1) != _T("\\"))
    strFilePath += _T("\\");
    }
    else
    return _T("");
    }
    else
    return _T("");

    if(lpMalloc)
    {
    lpMalloc->Free(pidl);
    lpMalloc->Release();
    }

    return strFilePath;
    }
    使用方法:T_SelectPath(_T("请选择一个目录"), _T("c:\\winnt"), hWnd);
      

  5.   

    CString strPath = T_SelectPath(_T("请选择一个目录"), _T("c:\\winnt"), hWnd);if(strPath.GetLength() > 0)
    {
     ....
    }