Is there a way I can specify a fixed starting directory for the broswe dialog to use, in the code below?
Code:
uses ShellAPI, ShlObj;
...
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;
Code:
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;
lpfn := BrowseDialogCallBack;
end;
lpItemID := SHBrowseForFolder(BrowseInfo);
if lpItemId <> nil then begin
SHGetPathFromIDList(lpItemID, TempPath);
Result := TempPath;
GlobalFreePtr(lpItemID);
end;
end;
Code:
procedure TForm1.Button1Click(Sender: TObject);
var
sFolder : string;
begin
sFolder := BrowseDialog('Select a folder',
BIF_RETURNONLYFSDIRS);
if sFolder <> '' then
ShowMessage('Selected: ' + #13#10 + sFolder);
end;
Steve (Delphi 2007 & XP)