在Inno Setup MsgBox上制作不可点击的OK按钮并改为倒计时

问题描述 投票:0回答:1

如何将“确定”按钮变成这样的倒计时器...

  • 5,4,3,2,1,0 【消息框自动关闭】不显示0

  • 继续进行设置程序。

按钮不应可点击且不会褪色。就像非活动窗口/按钮/框一样。

这个:

this one

不是这个:

not this one

我使用这个问题中的代码:如何在指定时间显示消息框?

inno-setup pascalscript
1个回答
3
投票

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

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

[Code]

function SetTimer(hWnd: LongWord; nIDEvent, uElapse: LongWord; 
  lpTimerFunc: LongWord): LongWord; external '[email protected] stdcall';
function KillTimer(hWnd: HWND; uIDEvent: LongWord): BOOL;
  external '[email protected] 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
函数,您需要 Inno Setup 6。如果您无法使用 Inno Setup 5,您可以使用
InnoTools InnoCallback
库中的 WrapCallback 函数。


像这样使用它:

CountdownMessageBox('Message here', 10);

Countdown dialog


相关问题:

© www.soinside.com 2019 - 2024. All rights reserved.