Search code examples
inno-setuppascalscript

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


This is a standard RTF document as used for the LicenseFile property in the [Setup] section of Inno Setup:

enter image description here

Is it possible to add a Print button to this page that would trigger to print the license agreement?


I saw a similar question with and answer (Adding a "print agreement" button to the licence page in Inno Setup) which I have just tried to implement. But this is what I get:

enter image description here

The button is in the wrong place and so this code does not seem to be fully Inno Setup 6 compatible?

So, in my script I have:

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

I am also not clear which code is correct to "print" this agreement.


Solution

  • It's not really about Inno Setup 6, but about WizardStyle=modern.

    1. If you want to place control at the bottom of a page, use coordinates relative to the size of the wizard, instead of absolute coordinates. Or even better, use coordinates relative to the controls you want to align with. That code apparently wanted to align the Print button with other buttons like Next, so do:

      PrintButton.Top := WizardForm.NextButton.Top;
      
    2. You are using WizardStyle=modern, which is larger than the classic wizard. At the time the InitializeWizard is called, the modern style is not yet applied. So even the Next button is not on its final place. To cater for that, use akBottom anchor (as NextButton does):

      PrintButton.Anchors := [akLeft, akBottom];
      

      It's a must also because the modern wizard is user-resizable, so you need to stick the button to the bottom, even when the wizard size changes later.

      See also Aligning custom button with the Inno Setup Cancel button

    3. Placing the button relative to WizardForm.InfoAfterPage.Left is nonsense, as that is always 0. You might want to use:

      PrintButton.Left :=
        WizardForm.OuterNotebook.Left + WizardForm.InnerNotebook.Left;
      
    4. Do not rely on the default sizes, which do not scale:

      enter image description here

      You can use the sizes of the other controls you want to align with:

      PrintButton.Width := WizardForm.NextButton.Width;
      PrintButton.Height := WizardForm.NextButton.Height;
      
    5. Always scale the offsets and sizes with ScaleX and ScaleY. See Placing image/control on Inno Setup custom page. Though if you apply all of the above, you won't have any fixed coordinates or sizes left.

    Now your code will work, no matter what style of Inno Setup wizard you use, or what DPI will your installer run on.

    enter image description here

    enter image description here