Shell BrowseForFolder preselected path

I have this call:

oShell.BrowseForFolder(Me.hwnd, "Select path:", 0, "C:\dir\") 

This opens a standard file browser dialog with the name "C: \ dir \" as root. My problem is that you cannot browse above the root folder. (as stated in the document http://msdn.microsoft.com/en-us/library/bb774065 (v = vs .85) .aspx )

Any suggestions on opening this dialog with the selected path and full viewing ability?

thanks

+6
source share
4 answers

A way to do this involves calling the base API, SHBrowseForFolder() .

Since you want the entire shell namespace to be accessible, you need to pass NULL as pidlRoot . To select the desired folder, you need to provide a callback in lpfn . Make this response back to BFFM_INITIALIZED by setting the selected folder. This selection is made by sending the BFFM_SETSELECTION message to the handle to the dialog box (passed to the callback function).

There is no code, because I do not have VB6, but I hope this outline of the method is enough for you to be on your way.

+6
source

The excellent Karl E Peterson website contains a sample that demonstrates the SHBrowseForFolder API SHBrowseForFolder with a callback, as in David Heffernan's answer.

KeyStuff Project

Take a look at MFolderBrowse.bas , a MFolderBrowse.bas routine that passes the BrowseCallbackProc callback function.

+5
source

Try the old CCRP project. He did a good job implementing the Browse dialog. I have used it in several of my projects, and it has properties to solve the problem you have.

+3
source

Here is the code for copying and pasting into the C ++ class:

 // static int CALLBACK Func::FolderBrowserCallback(HWND h_Dlg, UINT uMsg, LPARAM lParam, LPARAM lpData) { if (uMsg == BFFM_INITIALIZED) { // Requires Windows XP or higher SendMessageW(h_Dlg, BFFM_SETEXPANDED, TRUE, lpData); } return 0; } // returns an empty string u16_PathOut if an error occurrs or if the user cancels the dialog void Func::GetOpenFolder(HWND h_Owner, const WCHAR* u16_Title, // IN: Title at the top of dialog int s32_CsidlRoot, // IN: Root folder for treeview (CSIDL_DRIVES -> My Computer) const WCHAR* u16_Preselect, // IN: NULL or the folder to be preselected and expanded WCHAR* u16_PathOut) // OUT: selected path { u16_PathOut[0] = 0; // CoInitialize(NULL); // InitCommonControls(); ITEMIDLIST* pk_RootPIDL = NULL; // NULL -> Root = Desktop SHGetSpecialFolderLocation(h_Owner, s32_CsidlRoot, &pk_RootPIDL); BROWSEINFOW k_Info = {0}; k_Info.hwndOwner = h_Owner; k_Info.pidlRoot = pk_RootPIDL; k_Info.lpszTitle = u16_Title; k_Info.ulFlags = BIF_RETURNONLYFSDIRS | BIF_USENEWUI; if (u16_Preselect) { k_Info.lpfn = FolderBrowserCallback; k_Info.lParam = (LPARAM)u16_Preselect; } // DO NOT DISABLE Wow64FsRedirection HERE !! LPITEMIDLIST pk_IDlist = SHBrowseForFolderW(&k_Info); if (pk_IDlist) { SHGetPathFromIDListW(pk_IDlist, u16_PathOut); CoTaskMemFree(pk_IDlist); } CoTaskMemFree(pk_RootPIDL); } 
0
source

Source: https://habr.com/ru/post/896408/


All Articles