2

I based my setup in Larger "Select Components" page in Inno Setup . I would like to know how to center the setup window when I go to components page, since in small resolutions bottom buttons are not visible.

Community
  • 1
  • 1
DeXon
  • 419
  • 4
  • 12
  • The `WizardForm` has the `Center` method which can do that, but it centers the form even horizontally. Is that really what you want ? Don't you rather want to center it just vertically ? – TLama Mar 30 '14 at 12:41
  • I would like it vertically because where buttons are not visible is at the bottom. – DeXon Mar 30 '14 at 15:49

1 Answers1

2

Currently, there is no function to let you center the wizard form only in vertical direction. So, to make one you need to code a little bit. Here is function, that allows you to center forms in direction that you choose on the nearest monitor that the form covers the most:

[Code]
#ifdef UNICODE
  #define AW "W"
#else
  #define AW "A"
#endif

type
  HMONITOR = THandle;
  TMonitorInfo = record
    cbSize: DWORD;
    rcMonitor: TRect;
    rcWork: TRect;
    dwFlags: DWORD;
  end;

const
  MONITOR_DEFAULTTONULL = $0;
  MONITOR_DEFAULTTOPRIMARY = $1;
  MONITOR_DEFAULTTONEAREST = $2;

function GetMonitorInfo(hMonitor: HMONITOR; out lpmi: TMonitorInfo): BOOL;
  external 'GetMonitorInfo{#AW}@user32.dll stdcall';
function MonitorFromWindow(hwnd: HWND; dwFlags: DWORD): HMONITOR;
  external 'MonitorFromWindow@user32.dll stdcall';

procedure CenterForm(Form: TForm; Horz, Vert: Boolean);
var
  X, Y: Integer;
  Monitor: HMONITOR;
  MonitorInfo: TMonitorInfo;
begin
  if not (Horz or Vert) then
    Exit;
  Monitor := MonitorFromWindow(Form.Handle, MONITOR_DEFAULTTONEAREST);
  MonitorInfo.cbSize := SizeOf(MonitorInfo);
  if GetMonitorInfo(Monitor, MonitorInfo) then
  begin
    if not Horz then
      X := Form.Left
    else
      X := MonitorInfo.rcWork.Left + ((MonitorInfo.rcWork.Right -
        MonitorInfo.rcWork.Left) - Form.Width) div 2;
    if not Vert then
      Y := Form.Top
    else
      Y := MonitorInfo.rcWork.Top + ((MonitorInfo.rcWork.Bottom -
        MonitorInfo.rcWork.Top) - Form.Height) div 2;
    Form.SetBounds(X, Y, Form.Width, Form.Height);
  end;
end;

To implement it in the code you used, you need to modify the part when the page is being changed:

...

procedure CurPageChanged(CurPageID: Integer);
begin
  if CurpageID = wpSelectComponents then
  begin
    SaveComponentsPage(CompPagePositions);
    LoadComponentsPage(CompPagePositions, 200);
    CenterForm(WizardForm, False, True); // <- center the form only vertically
    CompPageModified := True;
  end
  else
  if CompPageModified then
  begin
    LoadComponentsPage(CompPagePositions, 0);
    CenterForm(WizardForm, False, True); // <- center the form only vertically
    CompPageModified := False;
  end;
end;
Community
  • 1
  • 1
TLama
  • 75,147
  • 17
  • 214
  • 392