// snippet by Matt Ginzton, http://www.maddogsw.com/ // usage governed by GPL: http://www.gnu.org/copyleft/gpl.txt // copy freely! no warranties whatsoever! // This code will try to use the "new" BrowseForFolders UI on Windows 2000, // which you can disable by removing the BIF_USENEWUI value from bi.ulFlags. int CALLBACK FillInFromBrowse_SetInitialDirHelper (HWND hWnd, UINT msg, LPARAM lParam, LPARAM lpData) { switch (msg) { case BFFM_INITIALIZED: ::SendMessage (hWnd, BFFM_SETSELECTION, TRUE, lpData); break; } return 0; } void FillInFromBrowse (HWND hTarget) { #ifndef BIF_NEWDIALOGSTYLE #define BIF_NEWDIALOGSTYLE 0x0040 #define BIF_USENEWUI (BIF_NEWDIALOGSTYLE | BIF_EDITBOX) #endif IMalloc* pMalloc; SHGetMalloc (&pMalloc); BROWSEINFO bi = {0}; char szBuf[MAX_PATH]; ::GetWindowText (hTarget, szBuf, MAX_PATH); bi.hwndOwner = hTarget; bi.ulFlags = BIF_USENEWUI | BIF_RETURNONLYFSDIRS; bi.lpfn = FillInFromBrowse_SetInitialDirHelper; bi.lParam = (LPARAM)szBuf; LPITEMIDLIST pidlDir = SHBrowseForFolder (&bi); if (pidlDir) { SHGetPathFromIDList (pidlDir, szBuf); ::SetWindowText (hTarget, szBuf); pMalloc->Free (pidlDir); } pMalloc->Release(); }