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); }
Elmue source share