InnoSetup:如何设置窗口中心

时间:2014-03-30 12:24:40

标签: inno-setup

我的设置基于 Larger "Select Components" page in Inno Setup。我想知道在进入组件页面时如何使设置窗口居中,因为在小分辨率下,底部按钮不可见。

1 个答案:

答案 0 :(得分:2)

目前,没有任何功能可让您仅在垂直方向上居中使用向导。所以,要制作一个,你需要编写一点代码。这是一个功能,它允许您将表单放在您在表格所涵盖的最近的监视器上选择的方向中心:

[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;

要在您使用的the code中实现它,您需要在更改页面时修改该部分:

...

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;