在 Inno Setup 中实现倒数N秒后激活按钮

2022-11-08,,,,

原文 http://restools.hanzify.org/article.asp?id=67

timectrl.dll 为一个 6.5 KB 的按钮激活时间控制插件。

 引用来自 Example1.iss,2009-1-19 12:35:12
; -- Example1.iss --
; restools
; http://restools.yeah.net
; 此插件同样可以使用在NSIS的安装程序中。
; 这只不过是演示一下没有什么是实现不了的,只是值不值得的问题,为了这么一个小功能而去编一个相对麻烦的插件,我觉得太过浪费时间了。
; 其实只要在 Windows 中,就可以外挂任何的东西,只不过看看究竟你的重心是在做安装程序,还是在做外挂。如果做一个外挂的插件比做这个安装程序还复杂,倒不如我自己编写安装程序的自由度还来得大。
; 时间仓促,所以编程可能会有点谬误,如有错误可以提出

[Setup]
AppName=我的程序
AppVerName=我的程序 版本 1.5
DefaultDirName={pf}\我的程序
DefaultGroupName=我的程序
UninstallDisplayIcon={app}\MyProg.exe
LicenseFile=license.txt

[Files]
Source: "MyProg.exe"; DestDir: "{app}"
Source: "Readme.txt"; DestDir: "{app}"; Flags: isreadme
Source: "timectrl.dll"; Flags: dontcopy

[Icons]
Name: "{group}\我的程序"; Filename: "{app}\MyProg.exe"

[code]
function starttimer(WizardFormHandle: HWND; ButtonHandle: HWND; ButtonCaption: PChar; RTime: UINT): BOOL; external 'starttimer@files:timectrl.dll stdcall';
//WizardFormHandle 向导窗口句柄
//ButtonHandle 下一步按钮句柄
//ButtonCaption 秒数倒数完毕后要在按钮上显示的文字
//RTime 剩余时间
function stoptimer(): BOOL; external 'stoptimer@files:timectrl.dll stdcall';

function IsWindowEnabled(hWnd: HWND): BOOL; external 'IsWindowEnabled@user32.dll stdcall';

procedure InitializeWizard();
begin
  WizardForm.LICENSEACCEPTEDRADIO.Hide;
  WizardForm.LICENSENOTACCEPTEDRADIO.Hide;
  WizardForm.LICENSEACCEPTEDRADIO.Checked := True;
  WizardForm.LICENSEMEMO.Height := 170;
  with TLabel.Create(WizardForm) do
  begin
    Parent := WizardForm.LicensePage;
    Top := 200;
    Left := 2;
    Caption := '如果你点击“我同意”进入下一页面,即表示你同意以上协议。';
  end;
end;

procedure DeinitializeSetup();
begin
  stoptimer();
end;

procedure CurPageChanged(CurPageID: Integer);
begin
//一定要别人先看协议20秒,即使返回欢迎页面,秒数倒数会停止,再进入协议秒数倒数继续
  if CurPageID = wpLicense then
      starttimer(WizardForm.Handle,WizardForm.NEXTBUTTON.Handle,'我同意(&I)',20)
  else
  if (CurPageID = wpWelcome) or (CurPageID = wpSelectDir) then
  begin
    stoptimer();
    WizardForm.NEXTBUTTON.Caption := '下一步(&N) >';
  end;
end;

function NextButtonClick(CurPageID: Integer): Boolean;
begin
  if (CurPageID = wpLicense) then
    Result := IsWindowEnabled(WizardForm.NextButton.Handle)
  else
    Result := True;
end;

点击这里下载脚本例子:
http://restools.hanzify.org/inno/timectrl/inno_timectrl.zip 

Inno Setup 中实现倒数N秒后激活按钮的相关教程结束。

《在 Inno Setup 中实现倒数N秒后激活按钮.doc》

下载本文的Word格式文档,以方便收藏与打印。