Reputation: 352
I am trying to create a splash screen for my installer in Inno Setup. I create a form that is displayed for 2 seconds at the beginning of the installer, but the image is not displayed in it.
Only when I use the ShowModal
function is it displayed, but it does not close after 2 seconds.
Here is my code:
[Code]
var
SplashForm: TSetupForm;
BIRegistry: TBitmapImage;
procedure SplashScreen;
begin
SplashForm := CreateCustomForm;
SplashForm.Position := poScreenCenter;
SplashForm.BorderStyle := bsNone;
BIRegistry := TBitmapImage.Create(SplashForm);
BIRegistry.Bitmap.LoadFromFile(ExpandConstant('{tmp}\regtoexe.bmp'));
BIRegistry.Parent := SplashForm;
BIRegistry.AutoSize := True;
SplashForm.ClientHeight := BIRegistry.Height;
SplashForm.ClientWidth := BIRegistry.Width;
SplashForm.Show;
Sleep(2000);
SplashForm.Close;
end;
procedure InitializeWizard;
begin
ExtractTemporaryFile('regtoexe.bmp');
SplashScreen;
What's wrong with this code?
Upvotes: 2
Views: 366
Reputation: 202118
That's because by calling Sleep
you freeze Windows message pump, so the image cannot draw.
Quick and dirty solution is to force repaint before the Sleep
:
SplashForm.Show;
SplashForm.Repaint;
Sleep(2000);
SplashForm.Close;
This is what Inno Setup Script Includes (ISSI) package was doing.
More correct way is to use the ShowModal
and have the modal window close automatically after specified time:
var
CloseSplashTimer: LongWord;
function SetTimer(hWnd, nIDEvent, uElapse, lpTimerFunc: LongWord): LongWord;
external '[email protected] stdcall';
function KillTimer(hWnd, nIDEvent: LongWord): LongWord;
external '[email protected] stdcall';
procedure CloseSplashProc(
H: LongWord; Msg: LongWord; IdEvent: LongWord; Time: LongWord);
begin
KillTimer(0, CloseSplashTimer);
SplashForm.Close;
end;
procedure SplashScreen;
begin
SplashForm := CreateCustomForm;
// rest of your splash window setup code
CloseSplashTimer := SetTimer(0, 0, 2000, CreateCallback(@CloseSplashProc));
SplashForm.ShowModal;
end;
Based on: MsgBox - Make unclickable OK Button and change to countdown - Inno Setup
Upvotes: 3