How can I display the BrowseForFolder dialog?
Applies To: C++Builder 1 or higher
Category: Knowledge Base

-
- Start a new application.
-
- Add a Button. Edit its OnClick event:
-
- #include <shlobj.hpp>
- void __fastcall TForm1::Button1Click(TObject *Sender)
- {
- LPMALLOC pMalloc;
- if(SHGetMalloc(&pMalloc) == NOERROR)
- {
- BROWSEINFO bi;
- char pszBuffer[MAX_PATH];
- LPITEMIDLIST pidl;
- bi.hwndOwner = Handle;
- bi.pidlRoot = NULL;
- bi.pszDisplayName = pszBuffer;
- bi.lpszTitle = "Please select a directory:";
- bi.ulFlags = BIF_RETURNFSANCESTORS |
- BIF_RETURNONLYFSDIRS;
- bi.lpfn = NULL;
- bi.lParam = 0;
- if((pidl = SHBrowseForFolder(&bi)) != NULL)
- {
- if(SHGetPathFromIDList(pidl, pszBuffer))
- {
- Caption = pszBuffer;
- }
- pMalloc->Free(pidl);
- }
- pMalloc->Release();
- }
- }
-
- When the user selects a directory, its path will be displayed in the caption bar.
C++Builder Developer's Network
Copyright © Yoto Yotov