-
SHBrowseForFolder
I need to use SHBrowseForFolder but have not been able to locate what I need to get the required behavior. It seems pretty simple, I need the routine to open as if the root of the dialog is the desktop so you see all the users drives, shares, etc. but I need to to open a folder. For example the user may be working in folder c:\A1, so when the folder dialog opens, you see all the drives, shares, etc, but the c:\A
-
continued
<hmmm, hit something on the keyboard and it submitted my question???> anyway, I need the c:\A1 directory to be open as the selected directory. Currently when I set the root, it does not show any directories above or at the same level as the root. So if I set c:\A1 as root, the user can only see directories below A1. Is there something simple I am missing, it seems what I am looking for would be the default behavior.
Thanks in advance
-
As far as I remember there is no way, because that is the designed behavior of SHBrowseForFolder.
-
It's possible by using a callback.
Code:
BROWSEINFO browseinfo;
// Fill in your browseinfo
...
// Add these
browseinfo.lParam = reinterpret_cast<LPARAM>(pszFolder);
browseinfo.lpfn = &SHBrowseForFolderCallbackProc;
where pszFolder is a pointer to a TCHAR containing your folder to open.
The callback function
Code:
int CALLBACK SHBrowseForFolderPIDLCallbackProc(HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData)
{
if (!lpData || !::IsWindow(hwnd))
return 0;
switch (uMsg)
{
case BFFM_INITIALIZED:
// Set the initial folder
::SendMessage(hwnd, BFFM_SETSELECTION, TRUE, lpData);
break;
}
return 0;
}
Change the TRUE in the sendmessage to FALSE when lpData is a PIDL.