Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

force SHBrowseForFolder() to show desired directory

I've been searching online and fighting this thing for over an hour and still can't seem to get it to work. Most people seem to be satisfied when they get it this far on forums etc. but mine still doesn't work. I'm trying to force the SHBrowseForFolder() function to start in a folder of my choosing.

char current[MAX_PATH];
strcpy(current,"C:\\Users");

char outbuf[MAX_PATH];
BROWSEINFO bis;
bis.hwndOwner = NULL;
bis.pidlRoot = NULL;
bis.pszDisplayName = outbuf;
bis.lpszTitle = (LPCSTR)"HERE";
bis.ulFlags = BIF_NEWDIALOGSTYLE|BIF_RETURNONLYFSDIRS;
bis.lpfn = NULL;
bis.lParam = (LPARAM)current;

SHBrowseForFolder(
    &bis
);

It seems like this should be a relatively simple task. :/ At the moment, the above code is still showing the default: the Desktop folder. Beyond starting in a specific folder, if possible, I'd also like it to ONLY show that folder and below, with no access to parent directories.

What am I missing here?

like image 783
user980058 Avatar asked Jul 04 '13 13:07

user980058


2 Answers

You can also send a BFFM_SETSELECTION message from your BrowseCallbackProc, like:

int FAR PASCAL BrowseNotify(HWND hWnd, UINT iMessage, long wParam, LPARAM lParam)
{   if (iMessage == BFFM_INITIALIZED)
    {   SendMessage(hWnd, BFFM_SETSELECTION, 1, (LPARAM) szInitialPathName);    // Set initial folder
        return 1;
    }
    return 0;
}
like image 74
Edward Clements Avatar answered Oct 24 '22 23:10

Edward Clements


Set the BFFCALLBACK (lpfn) to a BrowseCallbackProc. From there you can call SendMessage with BFFM_SETEXPANDED to specify the path of a folder to expand in the Browse dialog box.

See: http://msdn.microsoft.com/en-us/library/windows/desktop/bb773205(v=vs.85).aspx and http://msdn.microsoft.com/en-us/library/windows/desktop/bb762598(v=vs.85).aspx

From my experience, that folder dialog is a bit flaky - it often scrolls the desired directory out of view and looks suboptimal. Just one of the joys of Windows...

Also, there is no way I have discovered to get it to show only that directory and its subs. The parent directories always seem to be there.

like image 26
edtheprogrammerguy Avatar answered Oct 24 '22 21:10

edtheprogrammerguy