0

I'm trying to show marquee progress bar on TOutputMarqueeProgressWizardPage while doing a long operation. I use SetTimer function to call my UpdateProgress callback. The idea is taken from this thread. Here is my script:

[Setup]
AppId={{F25E1D25-DF59-4B37-AD32-1EBD5F6A3CA6}
AppName="My Program"
AppVersion=1.5
CreateAppDir=no
OutputBaseFilename=setup

[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"

[Files]
Source: "WhatsAppSetup.exe"; Flags: ignoreversion dontcopy

[Code]
var
  CustomPage: TOutputMarqueeProgressWizardPage;
  CustomPageAfterID: Integer;

procedure InitializeWizard;
begin
  CustomPage := CreateOutputMarqueeProgressPage('CreateOutputMarqueeProgressPage', 'ADescription');
  CustomPageAfterID := wpReady;  
end;

function SetTimer(Wnd: LongWord; IDEvent, Elapse: LongWord; TimerFunc: LongWord): LongWord;
external 'SetTimer@user32.dll stdcall';
function KillTimer(hWnd: LongWord; uIDEvent: LongWord): BOOL;
external 'KillTimer@user32.dll stdcall';

procedure UpdateProgress();
begin
  Log('Animating');
  CustomPage.Animate;
end;

function NextButtonClick(CurPageID: Integer): Boolean;
var
ResultCode: Integer;
Timer: LongWord;
begin
  Log('Page ID: ' + IntToStr(CurPageId));
  if CurPageID = CustomPageAfterID then begin
    try
      Timer := SetTimer(0, 0, 250, CreateCallback(@UpdateProgress));
      CustomPage.Show;
      ExtractTemporaryFile('WhatsAppSetup.exe');
      Exec(ExpandConstant('{tmp}\WhatsAppSetup.exe'), '--silent', '', SW_SHOW, ewWaitUntilTerminated, ResultCode);
      Sleep(20000);
    finally
      KillTimer(0, Timer);
      CustomPage.Hide;
    end;
  end;
  Result := True;
end;

However, my callback is called only once, here is an excerpt from output:

[20:59:38,970]   Extracting temporary file: C:\Users\user\AppData\Local\Temp\is-DCI5S.tmp\WhatsAppSetup.exe
[20:59:39,783]   Animating
[20:59:59,931]   Found 0 files to register with RestartManager.

How to fix that and animate progress bar periodically?

qloq
  • 689
  • 1
  • 5
  • 15
  • See [How to delay without freezing in Inno Setup](https://stackoverflow.com/q/39825271/850848) – That's an answer to your literal question. Though it might be XY problem. Why do you even have the `Sleep(20000)` there? – Martin Prikryl Mar 27 '23 at 19:10
  • Sorry, I don't understand your comment. I don't want to delay the work, I want progress bar to be animated while script is doing something. `Sleep` here emulates long operation additionally to `exec` of whatsapp installation. – qloq Mar 27 '23 at 22:56
  • My command (and the link) tells you that the Sleep freezes the GUI – and that's why the timer is not called. And it shows you how to implement the "sleep" in a way not to freeze the GUI. I still do not understand why you needs to "sleep" though. – Martin Prikryl Mar 28 '23 at 06:21

0 Answers0