如标题,想显示一个可以选择路径的对话框。以前用C++Builder,有个函数是SelectDirectoy,但不是Win32 API函数。

解决方案 »

  1.   

    ::SHBrowseForFolder(BROWSEINFO &bi)
      

  2.   

    up 最好找个源码
    SHBrowseForFolder涉及内容太多
      

  3.   

    char  lpBuffer[MAX_PATH], buf[1024]; 
    LPMALLOC pMalloc;
    SHGetMalloc(&pMalloc);BROWSEINFO bi;
    int i = 0;
    LPITEMIDLIST pidlBrowse;    // PIDL selected by user  memset(lpBuffer, 0, sizeof(lpBuffer));
    memset(buf, 0, sizeof(buf));

    // Fill in the BROWSEINFO structure.
    bi.hwndOwner = m_hWnd; 
    bi.pidlRoot = NULL;
    bi.pszDisplayName = lpBuffer; 
    bi.lpszTitle = "选择HTML文件存放的目录";
    bi.ulFlags = 0; 
    bi.lpfn = NULL;
    bi.lParam = 0;  
        
    // Browse for a folder and return its PIDL. 
    pidlBrowse = SHBrowseForFolder(&bi);
    if (pidlBrowse != NULL)
    {  
            // Show the display name, title, and file system path. 
            if (SHGetPathFromIDList(pidlBrowse, lpBuffer)) 
                //you got the path here         // Free the PIDL returned by SHBrowseForFolder. 
            pMalloc->Free(pidlBrowse);}
      

  4.   

    inline int CALLBACK BrowseCallbackProc(HWND hwnd, UINT uMsg, 
                                           LPARAM lParam, LPARAM lpData)
    {
        _TCHAR szDir[_MAX_PATH];    switch(uMsg)
        {
        case BFFM_INITIALIZED:        // 初始化
            break;    case BFFM_SELCHANGED:        // 路径改变
             if( SHGetPathFromIDList( (LPITEMIDLIST)lParam, szDir ) )
            SendMessage( hwnd, BFFM_SETSTATUSTEXT, 0, (LPARAM)szDir );
             break;
        
        default:
            break;
        }
        
        return 0;
    }void CDlgOptionCapture::OnPathOpen() 
    {
        // TODO: Add your control notification handler code here
        _TCHAR        pszDisplayName[MAX_PATH];
        BROWSEINFO    bi;
        LPITEMIDLIST    lpID;    // 设置参数
        bi.hwndOwner = GetSafeHwnd();    // Handle to the owner window
        bi.pidlRoot = NULL;             // Location of root folder
        bi.pszDisplayName = pszDisplayName;    // Folder name selected
        bi.lpszTitle = _T("选择路径");    // Title name
        bi.ulFlags = BIF_RETURNONLYFSDIRS | 
                          BIF_STATUSTEXT;         // Option flags
        bi.lpfn = BrowseCallbackProc;        // Callback function
        bi.lParam = 0;                  // LPARAM
        bi.iImage = NULL;                       // Image selected    lpID = SHBrowseForFolder( &bi );
        if( lpID != NULL )
        {
            if( SHGetPathFromIDList( lpID, pszDisplayName ) )
            {
                m_strPath = pszDisplayName;
                if( m_strPath[m_strPath.GetLength() - 1] != '\\' )
                    m_strPath += _T('\\');
                UpdateData( FALSE );
            }
        }
    }