uses
ShlObj;
function BrowseDialogCallBack(Wnd: HWnd; uMsg: UINT; lParam, lpData: LParam): Integer stdcall;
var
WA, R: TRect;
PT: TPoint;
begin
if uMsg = BFFM_INITIALIZED then
begin
WA := Screen.WorkAreaRect;
GetWindowRect(Wnd, R);
PT.X := ((WA.Right - WA.Left) div 2) - ((R.Right - R.Left) div 2);
PT.Y := ((WA.Bottom - WA.Top) div 2) - ((R.Bottom - R.Top) div 2);
MoveWindow(Wnd, PT.X, PT.Y, R.Right - R.Left, R.Bottom - R.Top, True);
SendMessage(Wnd, BFFM_SETSELECTION, Ord(True), Integer(lpData));
end;
Result := 0;
end;
function BrowseDirectoryDialog(const ATitle: string; const AFlag: Integer;
var Dir: string): Boolean;
var
lpItemID: PItemIDList;
BrowseInfo: TBrowseInfo;
DisplayName, TempPath: array[0..MAX_PATH] of Char;
begin
FillChar(BrowseInfo, SizeOf(TBrowseInfo), #0);
with BrowseInfo do
begin
hwndOwner := Application.Handle;
pszDisplayName := @DisplayName;
lpszTitle := PChar(ATitle);
ulFlags := AFlag;
lpfn := BrowseDialogCallBack;
lParam := Integer(PChar(Dir));
end;
lpItemID := ShlObj.SHBrowseForFolder(BrowseInfo);
Result := lpItemId <> nil;
if Result then
begin
ShlObj.SHGetPathFromIDList(lpItemID, TempPath);
Dir := TempPath;
GlobalFreePtr(lpItemID);
end;
end;
Cheers