Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add clickable links to custom Inno Setup WelcomeLabel?

Tags:

inno-setup

I have an Inno Setup program with a custom WelcomeLabel2 message.

[Messages]
WelcomeLabel2=Lorem ipsum dolor sit amet CLICK_HERE consectetur adipiscing elit.

I am trying to make the CLICK_HERE a clickable link to a website.

Another thing I am wondering is how to make this CLICK_HERE text bold.

How can I achieve this?

like image 609
Lucas Matos Avatar asked Dec 15 '22 06:12

Lucas Matos


1 Answers

It's not easy.

To create a label that is clickable whole, you can use a code like:

procedure OpenBrowser(Url: string);
var
  ErrorCode: Integer;
begin
  ShellExec('open', Url, '', '', SW_SHOWNORMAL, ewNoWait, ErrorCode);
end;

procedure LinkClick(Sender: TObject);
begin
  OpenBrowser('https://www.example.com/');
end;

procedure InitializeWizard;
var
  Link: TLabel;
begin
  Link := TLabel.Create(WizardForm);
  Link.Left := ???;
  Link.Top := ???;
  Link.Parent := WizardForm.WelcomePage;
  Link.Caption := 'CLICK_HERE';
  Link.OnClick := @LinkClick;
  Link.ParentFont := True;
  Link.Font.Style := Link.Font.Style + [fsUnderline, fsBold];
  Link.Font.Color := clBlue;
  Link.Cursor := crHand;
end;

See also Show License Agreement link in Inno Setup while installation.


Though to create a label that have just parts of its text clickable is a way more difficult. If the text fits on one line, it's doable by stacking three labels next to each other (first the leading static text, then link, followed by the trailing static text). But if the text does not fit on one line, it's not doable, as the labels would overlap each other.


Alternatively, you can create an RTF document with the link and present it using a read-only TRichEditViewer:

procedure InitializeWizard;
var
  RichViewer: TRichEditViewer;
begin
  RichViewer := TRichEditViewer.Create(WizardForm);
  RichViewer.Left := WizardForm.WelcomeLabel2.Left;
  RichViewer.Top := WizardForm.WelcomeLabel2.Top;
  RichViewer.Width := WizardForm.WelcomeLabel2.Width;
  RichViewer.Height := WizardForm.WelcomeLabel2.Height;
  RichViewer.Parent := WizardForm.WelcomeLabel2.Parent;
  RichViewer.BorderStyle := bsNone;
  RichViewer.TabStop := False;
  RichViewer.ReadOnly := True;
  WizardForm.WelcomeLabel2.Visible := False;
   
  RichViewer.RTFText :=
    '{\rtf1 Lorem ipsum dolor sit amet ' +
    '{\b {\field{\*\fldinst{HYPERLINK "https://www.example.com/" }}' + 
    '{\fldrslt{CLICK_HERE}}}} ' +
    'consectetur adipiscing elit.}';
end;

enter image description here

You need Unicode version (the only version as of Inno Setup 6) for this, see How to add clickable links to custom page in Inno Setup using RichEditViewer?

To change the link color, see Inno Setup - How to change the color of the hyperlink in RTF text?


As @Bill_Stewart commented, you should avoid starting the browser with elevated privileges. For a solution, see How to open a web site after uninstallation in non-elevated mode?

like image 100
Martin Prikryl Avatar answered Jan 18 '23 03:01

Martin Prikryl