[Back To Directory]

Browse To A Folder:

1. Open Borland C++ Builder.
2. Place a Button on the form.
3. Double click Button1.
4. Type the following red code in the button function:

//This is what the Button1 function should look like:

void __fastcall TForm1::Button1Click(TObject *Sender)
{
   BROWSEINFO BrowsingInfo;
   LPITEMIDLIST ItemID;
   char szDirPath[MAX_PATH];

   memset(&BrowsingInfo, 0, sizeof(BROWSEINFO));
   memset(szDirPath, 0, MAX_PATH);
   memset(szFolderName, 0, MAX_PATH);

   BrowsingInfo.hwndOwner = Application->Handle;
   BrowsingInfo.lpszTitle = "Select A Folder";
   BrowsingInfo.ulFlags = BIF_RETURNONLYFSDIRS;

   ItemID = SHBrowseForFolder(&BrowsingInfo);
   SHGetPathFromIDList(ItemID, szDirPath);

   Label1->Caption = szDirPath;
}
//---------------------------------------------------------------------------


15. Run the program, click Button1. Browse to and select a folder. Label1 will display the selected folder



[Back To Directory]