Mega Code Archive

 
Categories / Delphi / Examples
 

How to call windows explorer browser dialog

//this code will display the windows Explorer Browser Dialog unit Unit1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, FileCtrl,ShlObj; type TForm1 = class(TForm) Button1: TButton; dlb: TDirectoryListBox; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.DFM} function BrowseForFolder: string; var lpItemID: PItemIDList; BrowseInfo: TBrowseInfo; DisplayName: array[0..MAX_PATH] of char; TempPath: array[0..MAX_PATH] of char; begin FillChar(BrowseInfo, sizeof(TBrowseInfo), #0); with BrowseInfo do begin hwndOwner := Application.Handle; pszDisplayName := @DisplayName; lpszTitle := PChar(''); ulFlags := BIF_RETURNONLYFSDIRS; end; lpItemID := SHBrowseForFolder(BrowseInfo); if lpItemId <> nil then begin SHGetPathFromIDList(lpItemID, TempPath); GlobalFreePtr(lpItemID); Result := TempPath; end else Result := ''; end; procedure TForm1.Button1Click(Sender: TObject); begin dlb.Directory:=BrowseForFolder; end; end.