SHBrowseForFolder display with a root folder RRS feed

  • Question

  • When SHBrowseForFolder is used with a given root folder, the root folder is displayed at the bottom of the window, selected but unexpanded, both in Xp and in Vista (in both window styles).

    This is not coherent with the definition given in the documentation for BROWSEINFO Structure:  


    Pointer to an ITEMIDLIST structure (PIDL) that specifies the location of the root folder from which to start browsing. Only the specified folder and any subfolders that are beneath the specified folder in the namespace hierarchy appear in the dialog box. This member can be NULL; in that case, the namespace root is used.

    Copiled with VC++ Express 2008
    lundi 2 mars 2009 23:08

Toutes les réponses

  • I don't know how you are using SHBrowseForFolder. Filling the parameters correctly may be tricky.

    Anyway, SHBrowseForFolder works the way it is described in the documentation when you specify a root folder (that is, only the specified folder and subfolders appear in the dialogbox).

    You have to create a PIDL for the root directory. When you've done that, it is straitforward :

    (code is written with Unicode strings)

        WCHAR *rootFolder = L"c:\\users\\pierre";  
        // Get PIDL for root folder  
        LPITEMIDLIST  pIdl = NULL;  
        ULONG         chEaten;  
        ULONG         dwAttributes;  
        IShellFolder* pDesktopFolder;  
        if (SUCCEEDED(SHGetDesktopFolder(&pDesktopFolder)))  
            pDesktopFolder->ParseDisplayName(NULL, NULL, rootFolder, &chEaten, &pIdl, &dwAttributes);  
        // Store PIDL for root folder in BROWSEINFO  
        BROWSEINFO bi={0};  
        bi.pidlRoot = pIdl;  
        // Browse for directories, using root folder  
        LPITEMIDLIST lpID = SHBrowseForFolder(&bi);  
        if (lpID != NULL)  
            WCHAR pszSelectedFolder[MAX_PATH];  
            SHGetPathFromIDList(lpID, pszSelectedFolder);  
            return TRUE;  
        return FALSE;  


    • Proposé comme réponse MichaelGriess samedi 29 mars 2014 17:17
    • Non proposé comme réponse MichaelGriess samedi 29 mars 2014 17:20
    vendredi 6 mars 2009 10:52
    Auteur de réponse