Inno Setup 安装程序未显示前启动画面上的图像

Image on a splash screen before Inno Setup installer does not display

我正在尝试在 Inno Setup 中为我的安装程序创建启动画面。 我在安装程序开始时创建了一个显示2秒的表格,但其中没有显示图像。

只有在使用ShowModal功能时才显示,2秒后不关闭

这是我的代码:

[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;

这段代码有什么问题?

那是因为通过调用 Sleep 你冻结了 Windows 消息泵,所以图像无法绘制。


快速而肮脏的解决方案是在 Sleep:

之前强制重绘
SplashForm.Show;
SplashForm.Repaint;
Sleep(2000);
SplashForm.Close;

这就是 Inno Setup Script Includes (ISSI) 包所做的。


更正确的方法是使用 ShowModal 并让模式 window 在指定时间后自动关闭:

var
  CloseSplashTimer: LongWord;

function SetTimer(hWnd, nIDEvent, uElapse, lpTimerFunc: LongWord): LongWord;
  external 'SetTimer@User32.dll stdcall';
function KillTimer(hWnd, nIDEvent: LongWord): LongWord;
  external 'KillTimer@User32.dll 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;

基于: