谢谢!

解决方案 »

  1.   

    http://community.csdn.net/Expert/topic/3784/3784163.xml?temp=.7860376
      

  2.   

    LPITEMIDLIST pidl;
    LPITEMIDLIST pidlRoot;
    LPMALLOC lpMalloc; TCHAR pszPath[MAX_PATH];
    _tcscpy(pszPath, ""); BROWSEINFO bi = { m_hWnd, NULL, (char *)(LPCTSTR)pszPath, "请选择存放的路径:", BIF_BROWSEFORCOMPUTER  | BIF_RETURNONLYFSDIRS, NULL, 0L, 0};

    if (0 != SHGetSpecialFolderLocation(HWND_DESKTOP, CSIDL_DRIVES, &pidlRoot)) 
    {
    return;
    } if (NULL == pidlRoot) 
    {
    return;  
    } bi.pidlRoot = pidlRoot;  pidl = SHBrowseForFolder(&bi); 

    if (NULL != pidl)
    {
    SHGetPathFromIDList(pidl, pszPath);  m_strFilePath = pszPath;
    }
    else
    {
    return;
    }

    // Get the shell's allocator to free PIDLs 
    if (!SHGetMalloc(&lpMalloc) && (NULL != lpMalloc)) 

    if (NULL != pidlRoot)

    lpMalloc->Free(pidlRoot); 
    }  

    if (NULL != pidl) 

    lpMalloc->Free(pidl); 
    }

    lpMalloc->Release(); 
    }
      

  3.   


    void CSelFileDlg::OnAdddir() 
    {
    // TODO: Add your control notification handler code here
    LPMALLOC pMalloc;
    BROWSEINFO bi;
    LPITEMIDLIST pidl; 
             TCHAR m_directory[MAX_PATH];

    ::ZeroMemory(&bi, sizeof(bi));

    // Gets the Shell's default allocator
    if (::SHGetMalloc(&pMalloc) == NOERROR)
    {
    // Get help on BROWSEINFO struct - it's got all the bit settings.

    bi.hwndOwner=NULL;
            bi.pidlRoot=NULL;//为NULL,则已桌面为根,
    bi.lpszTitle=_T("请选择文件夹");//
    bi.ulFlags=BIF_RETURNONLYFSDIRS;
    bi.lpfn=NULL;
    bi.lParam=NULL;
    bi.pszDisplayName = m_directory; 
    // This next call issues the dialog box.
    if ((pidl = ::SHBrowseForFolder(&bi)) != NULL)
    {
    if (!::SHGetPathFromIDList(pidl, m_directory)) 
    pMalloc->Free(pidl); 
    //m_directory 就保存了你选择的文件夹
    }  
    pMalloc->Release();
    } // 
        m_bdirectory = true;
    }
      

  4.   

    CString sFolder;  //存放选定一个文件夹
        LPMALLOC pMalloc;    // Gets the Shell's default allocator
        if (::SHGetMalloc(&pMalloc) == NOERROR)
        {
            BROWSEINFO bi;
            char pszBuffer[MAX_PATH];
            LPITEMIDLIST pidl;        bi.hwndOwner = GetSafeHwnd();
            bi.pidlRoot = NULL;
            bi.pszDisplayName = pszBuffer;
            bi.lpszTitle = _T("Select a directory...");
            bi.ulFlags = BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS;
            bi.lpfn = NULL;
            bi.lParam = 0;        // This next call issues the dialog box.
            if ((pidl = ::SHBrowseForFolder(&bi)) != NULL)
            {
                if (::SHGetPathFromIDList(pidl, pszBuffer))
                { 
                // At this point pszBuffer contains the selected path
    sFolder = pszBuffer;
                }            // Free the PIDL allocated by SHBrowseForFolder.
                pMalloc->Free(pidl);
            }
            // Release the shell's allocator.
            pMalloc->Release();
        }
      

  5.   

    没有一种如“OPENFILENAME”好用的东西吗?