Search code examples
inno-setuppascalscript

Inno Setup button caption with line breaks


I am trying to create a button caption that contains a line break:

Button.Caption := 'Line1' + #13#10 + 'Line2';

However, the standard line break character #13#10 does not appear to work in this case as I am getting:

Line1Line2

displayed on the button. What is the correct syntax to break a button caption across more than one line?


Solution

  • Based on Newline character in caption of button (in Delphi):

    function GetWindowLong(Wnd: HWnd; Index: Integer): LongInt;
      external 'GetWindowLongW@user32.dll stdcall';
    function SetWindowLong(Wnd: HWnd; Index: Integer; NewLong: LongInt): LongInt;
      external 'SetWindowLongW@user32.dll stdcall';
    
    const
      GWL_STYLE = -16;
      BS_MULTILINE = $2000;
    
    procedure InitializeWizard();
    var
      Button: TNewButton;
    begin
      Button := TNewButton.Create(WizardForm);
      Button.Left := ScaleX(16);
      Button.Top := WizardForm.NextButton.Top - ScaleX(8);
      Button.Width := WizardForm.NextButton.Width;
      Button.Height := WizardForm.NextButton.Height + ScaleY(16);
      Button.Parent := WizardForm;
    
      SetWindowLong(Button.Handle, GWL_STYLE, 
        GetWindowLong(Button.Handle, GWL_STYLE) or BS_MULTILINE);
    
      Button.Caption := 'foo' + #13#10 + 'bar';
    end;
    

    Button with new line