请问在MFC中如何实现类似VB中的CDirList控件的功能,即能选择某一个目录

解决方案 »

  1.   

    刚好有这么一个类,告诉我你的email,发一份给你
      

  2.   

    char Dir[128] = "abcdefg";
    BROWSEINFO bi; 
    ITEMIDLIST *pidl; 
    bi.hwndOwner = NULL; 
    bi.pidlRoot = NULL; 
    bi.pszDisplayName = Dir; 
    bi.lpszTitle = "Select a directory"; 
    bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_DONTGOBELOWDOMAIN; 
    bi.lpfn = NULL; 
    bi.lParam = 0; 
    bi.iImage = 0; 
    pidl = SHBrowseForFolder( &bi ); 
    /* Display "Select Folder" dialog 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;
      

  3.   

    #include <Shlobj.h>Shell32.lib     LPMALLOC pMalloc;
        /* Gets the Shell's default allocator */
        if (::SHGetMalloc(&pMalloc) == NOERROR)
        {
            BROWSEINFO bi;
            char pszBuffer[MAX_PATH];
            LPITEMIDLIST pidl;
            // Get help on BROWSEINFO struct - it's got all the bit settings.
            bi.hwndOwner = GetSafeHwnd();
            bi.pidlRoot = NULL;
            bi.pszDisplayName = pszBuffer;
            bi.lpszTitle = /*_T("Select a Starting Directory");*/NULL;
            bi.ulFlags = BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS |BIF_STATUSTEXT ;
            bi.lpfn = NULL;
            bi.lParam = 0;
            // This next call issues the dialog box.
            if ((pidl = ::SHBrowseForFolder(&bi)) != NULL)
            {
                if (::SHGetPathFromIDList(pidl, pszBuffer))
                { 
    AfxMessageBox(pszBuffer, MB_OK);
                // At this point pszBuffer contains the selected path */.
    //                DoingSomethingUseful(pszBuffer);
                }
                // Free the PIDL allocated by SHBrowseForFolder.
                pMalloc->Free(pidl);
            }
            // Release the shell's allocator.
            pMalloc->Release();
        }