Mirror

How to programmatically change the size of the TOpenDialog window (Views: 100)


Problem/Question/Abstract:

Is there a way to programmatically change the size of the TOpenDialog window so that more files will be shown? In Win98, the user can drag the dialog window to increase its size. Can the window size be increased under program control?

Answer:

The OnShow event seems to be a bit too early to do it. It has to be delayed a bit. Like this:

type
  TForm1 = class(TForm)
    Button1: TButton;
    OpenDialog1: TOpenDialog;
    procedure Button1Click(Sender: TObject);
    procedure OpenDialog1Show(Sender: TObject);
  private
    { Private declarations }
    procedure MoveDialog(var Msg: TMessage); message WM_USER;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
begin
  if OpenDialog1.Execute then
    Caption := OpenDialog1.FileName;
end;

procedure TForm1.OpenDialog1Show(Sender: TObject);
begin
  PostMessage(Self.Handle, WM_USER, 0, 0);
end;

function GetDesktopWorkArea: TRect;
begin
  if not SystemParametersInfo(SPI_GETWORKAREA, 0, @Result, 0) then
    Result := Rect(0, 0, Screen.Width, Screen.Height);
end;

procedure TForm1.MoveDialog(var Msg: TMessage);
var
  rec: TRect;
  wh: HWND;
  l, t, r, b: Integer;
begin
  wh := Windows.GetParent(OpenDialog1.Handle);
  {if GetWindowRect(wh, rec) then}
  if IsWindow(wh) then
  begin
    rec := GetDesktopWorkArea;
    l := rec.Left;
    t := rec.Top;
    r := rec.Right;
    b := rec.Bottom;
    MoveWindow(wh, l, t, r, b, True);
  end;
end;

<< Back to main page