Inno Setup Progress Messages.

I’ve been working on an installer using Inno Setup and I came across this nice little piece of Inno Setup script code that allows you to add a percent done, elapsed time, and estimated time value during install. It works really well and adds a nice touch so I thought I would share. :slight_smile:

[quote]

[Code]
function GetTickCount: DWORD;
external ‘GetTickCount@kernel32.dll stdcall’;

var
StartTick: DWORD;
PercentLabel: TNewStaticText;
ElapsedLabel: TNewStaticText;
RemainingLabel: TNewStaticText;

function TicksToStr(Value: DWORD): string;
var
I: DWORD;
Hours, Minutes, Seconds: Integer;
begin
I := Value div 1000;
Seconds := I mod 60;
I := I div 60;
Minutes := I mod 60;
I := I div 60;
Hours := I mod 24;
Result := Format(’%.2d:%.2d:%.2d’, [Hours, Minutes, Seconds]);
end;

procedure InitializeWizard;
begin
PercentLabel := TNewStaticText.Create(WizardForm);
PercentLabel.Parent := WizardForm.ProgressGauge.Parent;
PercentLabel.Left := 0;
PercentLabel.Top := WizardForm.ProgressGauge.Top +
WizardForm.ProgressGauge.Height + 12;

ElapsedLabel := TNewStaticText.Create(WizardForm);
ElapsedLabel.Parent := WizardForm.ProgressGauge.Parent;
ElapsedLabel.Left := 0;
ElapsedLabel.Top := PercentLabel.Top + PercentLabel.Height + 4;

RemainingLabel := TNewStaticText.Create(WizardForm);
RemainingLabel.Parent := WizardForm.ProgressGauge.Parent;
RemainingLabel.Left := 0;
RemainingLabel.Top := ElapsedLabel.Top + ElapsedLabel.Height + 4;
end;

procedure CurPageChanged(CurPageID: Integer);
begin
if CurPageID = wpInstalling then
StartTick := GetTickCount;
end;

procedure CancelButtonClick(CurPageID: Integer; var Cancel, Confirm: Boolean);
begin
if CurPageID = wpInstalling then
begin
Cancel := False;
if ExitSetupMsgBox then
begin
Cancel := True;
Confirm := False;
PercentLabel.Visible := False;
ElapsedLabel.Visible := False;
RemainingLabel.Visible := False;
end;
end;
end;

procedure CurInstallProgressChanged(CurProgress, MaxProgress: Integer);
var
CurTick: DWORD;
begin
CurTick := GetTickCount;
PercentLabel.Caption :=
Format(‘Done: %.2f %%’, [(CurProgress * 100.0) / MaxProgress]);
ElapsedLabel.Caption :=
Format(‘Elapsed: %s’, [TicksToStr(CurTick - StartTick)]);
if CurProgress > 0 then
begin
RemainingLabel.Caption :=
Format(‘Remaining: %s’, [TicksToStr(
((CurTick - StartTick) / CurProgress) * (MaxProgress - CurProgress))]);
end;
end;[/quote]

Thank You and I will be trying this soon.

Another cool thing is it exposes the curPageChanged method. After a lot of trial and error and reading the docs I found that you can use this to manipulate a lot of the messages in each step of the wizard.

procedure CurPageChanged(CurPageID: Integer); begin if CurPageID = wpInstalling then StartTick := GetTickCount; end;

For instance add a custom title during install:

procedure CurPageChanged(CurPageID: Integer); begin if CurPageID = wpWelcome then WizardForm.Caption := 'Welcome to MyApp Setup!'; if CurPageID = wpInstalling then StartTick := GetTickCount; end;

Add a custom title and message at app finish:

procedure CurPageChanged(CurPageID: Integer); begin if CurPageID = wpFinished then WizardForm.Caption := 'MyApp Installation Complete!'; WizardForm.FinishedLabel.Caption := 'Congratulations! MyApp installation is complete! Enjoy!' if CurPageID = wpWelcome then WizardForm.Caption := 'Welcome to MyApp Setup!'; if CurPageID = wpInstalling then StartTick := GetTickCount; end;

:slight_smile: