将打印按钮添加到 Inno Setup 中的许可证页面(为 Inno Setup 6 重新访问)

Adding a Print button to the License page in Inno Setup (revisited for Inno Setup 6)

这是用于 Inno Setup [Setup] 部分中的 LicenseFile 属性 的标准 RTF 文档:

是否可以向此页面添加打印按钮以触发打印许可协议?


我看到了一个类似的问题和答案 (Adding a "print agreement" button to the licence page in Inno Setup),我刚刚尝试实现它。但这就是我得到的:

按钮位置错误,因此此代码似乎不完全兼容 Inno Setup 6?

所以,在我的脚本中我有:

[Setup]
LicenseFile=..\..\..\EULA\EULA.rtf

[Code]
var PrintButton: TButton;

procedure PrintButtonClick(Sender: TObject);
var ResultCode :integer;
begin
    log('test');
    ExtractTemporaryFile('EULA.rtf');
    //if not ShellExec('Print', ExpandConstant('{tmp}\EULA.rtf'),
    //     '', '', SW_SHOW, ewNoWait, ResultCode) then
    if not ShellExec('', ExpandConstant('{tmp}\EULA.rtf'),
         '', '', SW_SHOW, ewNoWait, ResultCode) then
    log('test');
end;

procedure InitializeWizard();
begin
    PrintButton := TButton.Create(WizardForm);
    PrintButton.Caption := '&Print...';
    PrintButton.Left := WizardForm.InfoAfterPage.Left + 96;
    PrintButton.Top := WizardForm.InfoAfterPage.Height + 88;
    PrintButton.OnClick := @PrintButtonClick;
    PrintButton.Parent := WizardForm.NextButton.Parent;
end;

procedure CurPageChanged(CurPage: Integer);
begin
    PrintButton.Visible := CurPage = wpLicense;
end;

我也不清楚“打印”此协议的正确代码。

这并不是关于 Inno Setup 6,而是关于 WizardStyle=modern

  1. 如果要将控件放置在页面底部,请使用相对于向导大小的坐标,而不是绝对坐标。或者更好的是,使用相对于要对齐的控件的坐标。该代码显然希望将 Print 按钮与 Next 等其他按钮对齐,所以:

    PrintButton.Top := WizardForm.NextButton.Top;
    
  2. 您正在使用 WizardStyle=modern,它比经典向导更大。在调用 InitializeWizard 时,尚未应用现代风格。因此,即使 Next 按钮也不在其最终位置。为此,请使用 akBottom 锚点(如 NextButton 所做的那样):

    PrintButton.Anchors := [akLeft, akBottom];
    

    这也是必须的,因为现代向导是用户可调整大小的,因此您需要将按钮粘贴到底部,即使向导大小稍后更改也是如此。

    另见

  3. 相对于 WizardForm.InfoAfterPage.Left 放置按钮是无稽之谈,因为它总是 0。您可能想使用:

    PrintButton.Left :=
      WizardForm.OuterNotebook.Left + WizardForm.InnerNotebook.Left;
    
  4. 不要依赖不缩放的默认尺寸:

    您可以使用要对齐的其他控件的大小:

    PrintButton.Width := WizardForm.NextButton.Width;
    PrintButton.Height := WizardForm.NextButton.Height;
    
  5. 始终使用 ScaleX and ScaleY. See 缩放偏移量和大小。虽然如果您应用以上所有内容,您将没有任何固定的坐标或尺寸。

现在,无论您使用何种风格的 Inno Setup 向导,或者您的安装程序 运行 使用何种 DPI,您的代码都可以正常工作。