Needed this myself the other week in D7, works like a charm ....
The functions :
function BrowseDialog (const Title: string; const Flag: integer): string;
var
lpItemID : PItemIDList;
BrowseInfo : TBrowseInfo;
DisplayName : array[0..MAX_PATH] of char;
TempPath : array[0..MAX_PATH] of char;
begin
Result:='';
FillChar(BrowseInfo, sizeof(TBrowseInfo), #0);
with BrowseInfo do begin
hwndOwner := Application.Handle;
pszDisplayName := @DisplayName;
lpszTitle := PChar(Title);
ulFlags := Flag;
end;
lpItemID := SHBrowseForFolder(BrowseInfo);
if lpItemId <> nil then begin
SHGetPathFromIDList(lpItemID, TempPath);
Result := TempPath;
GlobalFreePtr(lpItemID);
end;
end;
function BrowseDialogCallBack(Wnd: HWND; uMsg: UINT; lParam, lpData: LPARAM)
: integer stdcall;
var
wa, rect : TRect;
dialogPT : TPoint;
begin
//center in work area
if uMsg = BFFM_INITIALIZED then
begin
wa := Screen.WorkAreaRect;
GetWindowRect(Wnd, Rect);
dialogPT.X := ((wa.Right-wa.Left) div 2) -
((rect.Right-rect.Left) div 2);
dialogPT.Y := ((wa.Bottom-wa.Top) div 2) -
((rect.Bottom-rect.Top) div 2);
MoveWindow(Wnd,
dialogPT.X,
dialogPT.Y,
Rect.Right - Rect.Left,
Rect.Bottom - Rect.Top,
True);
end;
Result := 0;
end; (*BrowseDialogCallBack*)
function BrowseDialog1(const Title: string; const Flag: integer): string;
var
lpItemID : PItemIDList;
BrowseInfo : TBrowseInfo;
DisplayName : array[0..MAX_PATH] of char;
TempPath : array[0..MAX_PATH] of char;
begin
Result:='';
FillChar(BrowseInfo, sizeof(TBrowseInfo), #0);
with BrowseInfo do begin
hwndOwner := Application.Handle;
pszDisplayName := @DisplayName;
lpszTitle := PChar(Title);
ulFlags := Flag;
lpfn := BrowseDialogCallBack;
end;
lpItemID := SHBrowseForFolder(BrowseInfo);
if lpItemId <> nil then begin
SHGetPathFromIDList(lpItemID, TempPath);
Result := TempPath;
GlobalFreePtr(lpItemID);
end;
end;
And on the form :
procedure Tfmain.Button1Click(Sender: TObject);
var
iflag : integer;
stitle : string;
sfolder : string;
begin
ipath.setfocus;
iflag := BIF_RETURNONLYFSDIRS;
sFolder := BrowseDialog1(sTitle, iFlag);
if (sfolder <> '') then
ipath.text := sfolder;
end;
--> BrowseDialog1 shows a centered dialog whereas Browsedialog doesn't
--> Found all this on delphi.about.com or so ... (
Merry Christmas & Happy New Year
Lode Deleu
Orca
Gent - Belgium
----- Original Message -----
From: "Martin Kiener" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Tuesday, December 26, 2006 6:12 PM
Subject: Browse folder dialogbox, Delphi 7
> Hello,
> I would like to use in my application a dialog box to browse the folders
> and to retrive a path. The IDE of Delphi 7 shows such a box, if you select
> "Projects/Options/Directories" and then you click on the Ellipsis button
> (...) of Output Directory, then a dialog box is shown in which you can
> browse the directories and choose your output directory. I would like such
> a dialog box to reztrieve a path which I can use later in my application.
>
> Is such a component available? The components which are offered by the
> component palette are all more specialized. Have I to develope a new
> component? Which is the best way to learn to do this?
>
> Many thanks
> Martin Kiener
> _______________________________________________
> Delphi mailing list -> [email protected]
> http://www.elists.org/mailman/listinfo/delphi
_______________________________________________
Delphi mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi