Test OK for WinXP & Win98:
Force Opendialog Only Open 'C:/';
type
TForm1 = class(TForm)
OpenDialog1: TOpenDialog;
Button1: TButton;
Memo1: TMemo;
procedure OpenDialog1FolderChange(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
Busy:Boolean;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure SetOpenDialogDir(hWnd: HWND; Path: string;var Busy:Boolean);
const
ID_FILENAME_98 = 1152;
ID_FILENAME_WIN2K=1148;
ID_OK = 1;
var
hFileName: THandle;
hOK: THandle;
Buff:string[255];
begin
if Busy then exit;
Busy:=True;
if Win32MajorVersion >= 5 then
begin
hFileName:= GetDlgItem(GetParent(hWnd), ID_FILENAME_WIN2K);
hFileName:=FindWindowEx(hFileName,0,'ComboBox',nil);
hFileName:=FindWindowEx(hFileName,0,'Edit',nil);
end else hFileName := GetDlgItem(GetParent(hWnd), ID_FILENAME_98);
hOK := GetDlgItem(GetParent(hWnd), ID_OK);
GetWindowText(hFileName,@Buff[1],Length(Buff));
if LowerCase(Buff)=LowerCase(Path) then exit;
SetWindowText(hFileName, pchar(Path));
SendMessage(hOK, WM_LBUTTONDOWN, MK_LBUTTON, MAKEWORD(0, 0));
SendMessage(hOK, WM_LBUTTONUP, MK_LBUTTON, MAKEWORD(0, 0));
Busy :=False;
end;
procedure TForm1.OpenDialog1FolderChange(Sender: TObject);
begin
SetOpenDialogDir(OpenDialog1.Handle, 'C:/',Busy);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
OpenDialog1.Execute;
end;