inno-setup - MsgBox - 制作不可点击的确定按钮并更改为倒计时 - Inno Setup

标签 inno-setup pascalscript

如何将 OK 按钮变成这样的倒数计时器...

  • 5,4,3,2,1,0 [MsgBox自动关闭]不显示0

  • 继续设置过程。

按钮不应该是可点击的和淡出的。就像不活动的窗口/按钮/框。

这个:

this one

不是这个:

not this one

我使用这个问题的代码:How to show a message box for a specified time?

最佳答案

没有具有此类功能的内置函数。既不在 Inno Setup 中,也不在 WinAPI 中。

您必须自己实现对话框并使用计时器来实现倒计时。

[Code]

function SetTimer(hWnd: LongWord; nIDEvent, uElapse: LongWord; 
  lpTimerFunc: LongWord): LongWord; external 'SetTimer@user32.dll stdcall';
function KillTimer(hWnd: HWND; uIDEvent: LongWord): BOOL;
  external 'KillTimer@user32.dll stdcall';

var
  CountdownButton: TNewButton;
  Countdown: Integer;

procedure UpdateCountDownButtonCaption;
begin
  CountdownButton.Caption := Format('%d sec', [Countdown]);
end;

procedure CountdownProc(
  H: LongWord; Msg: LongWord; IdEvent: LongWord; Time: LongWord);
begin
  Dec(Countdown);
  if Countdown = 0 then
  begin
    CountdownButton.Enabled := True;
    TForm(CountdownButton.Parent).Close;
  end
    else
  begin
    UpdateCountDownButtonCaption;
  end;
end;

procedure CountdownMessageBoxCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
  { Prevent the dialog from being close by the X button and Alt-F4 }
  CanClose := CountdownButton.Enabled;
end;

procedure CountdownMessageBox(Message: string; Seconds: Integer);
var
  Form: TSetupForm;
  MessageLabel: TLabel;
  Timer: LongWord;
begin
  Form := CreateCustomForm;
  try
    Form.ClientWidth := ScaleX(256);
    Form.ClientHeight := ScaleY(96);
    Form.Caption := 'Information';
    Form.Position := poMainFormCenter;
    Form.OnCloseQuery := @CountdownMessageBoxCloseQuery;

    MessageLabel := TLabel.Create(Form);
    MessageLabel.Top := ScaleY(16);
    MessageLabel.Left := ScaleX(16);
    MessageLabel.AutoSize := True;
    MessageLabel.Caption := Message;
    MessageLabel.Parent := Form;

    if CountdownButton <> nil then
      RaiseException('Countdown in progress already');

    Countdown := Seconds;

    CountdownButton := TNewButton.Create(Form);
    CountdownButton.Parent := Form;
    CountdownButton.Width := ScaleX(88);
    CountdownButton.Height := ScaleY(26);
    CountdownButton.Left :=
      Form.ClientWidth - CountdownButton.Width - ScaleX(18);
    CountdownButton.Top :=
      Form.ClientHeight - CountdownButton.Height - ScaleX(11);
    UpdateCountDownButtonCaption;
    CountdownButton.Name := 'CountdownButton';
    CountdownButton.ModalResult := mrOk;
    CountdownButton.Default := True;
    CountdownButton.Enabled := False;

    Timer := SetTimer(0, 0, 1000, CreateCallback(@CountdownProc));

    try
      Form.ShowModal();
    finally
      KillTimer(0, Timer);
    end;
  finally
    Form.Free();
    CountdownButton := nil;
  end;
end;  

CreateCallback function ,您需要 Inno Setup 6。如果您坚持使用 Inno Setup 5,您可以使用 InnoTools InnoCallback 中的 WrapCallback 函数图书馆。


像这样使用它:

CountdownMessageBox('Message here', 10);

Countdown dialog


相关问题:

关于inno-setup - MsgBox - 制作不可点击的确定按钮并更改为倒计时 - Inno Setup,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40446269/

相关文章:

Java FX 应用程序安装在同一目录中

inno-setup - TNewCheckListBox 选中未更新

inno-setup - 在 Inno Setup 创建页面中,用户可以从安装文件中打包的文件夹中选择文件

inno-setup - 更改 Inno Setup 单选按钮(许可协议(protocol))字体颜色

class - 我可以在 Inno Setup 中创建自己的类(class)或单元吗?

installation - 在使用Inno Setup进行安装之前如何运行文件

inno-setup - Inno Setup 对新安装和更新的响应是否不同?

java - 如何向 javafx-maven-plugin 创建的 exe 安装程序添加许可证?

inno-setup - 安装所有文件后运行的代码

java - 在 Inno Setup 中使用 AfterInstall 时如何运行包含空格的路径(捆绑 JRE)的命令