杉宫竹苑工作室

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 2341|回复: 1

NSIS 5秒倒计时

[复制链接]
发表于 2017-2-25 21:29:02 | 显示全部楼层 |阅读模式

正式会员享受无限制浏览网站功能和高速网盘下载,赶快加入本站吧!

您需要 登录 才可以下载或查看,没有账号?立即注册

x
  1. ; nsi编译脚本
  2. ; 到达指定时间自动执行所需操作的脚本例子
  3. ; 编写:zhfi <zhfi1022@tom.com>
  4. ; 注意:必须使用Delay、RealProgress以及新版的InstallOptionEx插件方可实现!

  5. ;--------------------------------
  6. ;添加插件目录
  7. !AddPluginDir .\

  8. !include LogicLib.nsh

  9. ;定义INI文件
  10. !define INI $PLUGINSDIR\Auto.ini
  11. ;定义自定义页面句柄存放变量
  12. var hwnd

  13. SetCompressor /SOLID lzma
  14. SetCompressorDictSize 8

  15. Name AutoRun
  16. OutFile AutoRun.exe

  17. ;--------------------------------

  18. ;自定义页面
  19. Page custom SetCustom LeaveCustom

  20. Section Nil
  21. SectionEnd

  22. Function .onInit
  23. ;创建临时插件目录并释放INI文件
  24.   InitPluginsDir
  25.   File /oname=${INI} "Auto.ini"
  26. FunctionEnd

  27. Function .onGUIEnd
  28. ;释放插件
  29.   Delay::Free
  30.   RealProgress::Unload
  31. FunctionEnd

  32. Function SetCustom
  33. Var /GLOBAL PageDone
  34. IntCmp $PageDone 1 free
  35. InstallOptionsEx::initDialog /NOUNLOAD ${INI}
  36. Pop $hwnd
  37. GetDlgItem $0 $hwnd 1201
  38. ;此处的倒计时时间(5秒)必须与ini中定义一致!
  39. Delay::DelayButton /NOUNLOAD $0 5 ""
  40. ;获取进度条控件
  41. RealProgress::UseProgressBar /NOUNLOAD 1203
  42. ;控制进度条进度
  43. ;参数(进度百分比):开始时 每秒增加量 结束时
  44. RealProgress::GradualProgress /NOUNLOAD 1 20 100
  45. StrCpy $PageDone 1
  46. InstallOptionsEx::Show
  47. Goto end
  48. free:
  49. end:

  50. FunctionEnd

  51. Function LeaveCustom
  52. ;这个函数中存放你要执行的操作代码
  53. MessageBox mb_ok "该消息框由NSIS自动执行!"
  54. FunctionEnd

  55. INI配置文件
  56. ;NumFields必须不能为0
  57. ;TimeOut表示自动退出的执行时间(单位:毫秒)
  58. [Settings]
  59. NumFields=4
  60. TimeOut=5000
  61. Title="在指定时间执行预定操作的脚本例子"
  62. [Field 1]
  63. Type=Label
  64. Text=离自动XX还有:
  65. Left=30
  66. Right=90
  67. Top=10
  68. Bottom=25

  69. [Field 2]
  70. Type=Label
  71. Text=XX
  72. Left=95
  73. Right=105
  74. Top=10
  75. Bottom=25

  76. [Field 3]
  77. Type=Label
  78. Text=秒
  79. Left=115
  80. Right=130
  81. Top=10
  82. Bottom=30

  83. [Field 4]
  84. Type=ProgressBar
  85. Text=
  86. Left=15
  87. Right=150
  88. Top=30
  89. Bottom=50
复制代码


回复

使用道具 举报

 楼主| 发表于 2017-2-25 21:29:28 | 显示全部楼层
本帖最后由 Share 于 2017-2-26 11:25 编辑

5381238604754631559.jpg
  1. ;程序需要Delay.dll支持实现效果。资源在网盘
  2. Name                 "Delay"
  3. OutFile              "demo.exe"
  4. Caption              "Delay the next button"
  5. SetCompressor        lzma
  6. ShowInstDetails      show

  7. !AddPluginDir        "."
  8. !include             MUI.nsh

  9. !define MUI_CUSTOMFUNCTION_ABORT OnUserAbort

  10. !define MUI_PAGE_CUSTOMFUNCTION_SHOW LicensePage
  11. !define MUI_PAGE_CUSTOMFUNCTION_LEAVE LicensePageLeave
  12. !insertmacro MUI_PAGE_LICENSE "license.txt"
  13. !insertmacro MUI_PAGE_INSTFILES

  14. !insertmacro MUI_LANGUAGE English

  15. Section
  16. DetailPrint "Do nothing..."
  17. SectionEnd


  18. Function LicensePage
  19. GetDlgItem $0 $HWNDPARENT 1

  20. ;NOTE: Plugins must be keep loaded while count, else installer may crash. (切记切记)
  21. ;SYNTAX: Delay::DelayButton /NOUNLOAD HWND DELAY_COUNT DISPLAY_STRING
  22. ;DISPLAY_STRING separate by |
  23. Var /GLOBAL PageDone
  24. IntCmp $PageDone 1 free
  25. Delay::DelayButton /NOUNLOAD $0 5 "A|B|C|D|E"
  26. ;此例子到时为5秒
  27. ; Delay::DelayButton /NOUNLOAD $0 5 ""
  28. StrCpy $PageDone 1
  29. Goto end
  30. free:
  31. Delay::Free
  32. end:
  33. FunctionEnd

  34. Function LicensePageLeave
  35. ;Case installer unload the plugins after this command
  36. Delay::Free
  37. FunctionEnd

  38. Function OnUserAbort
  39. ;If user press Cancel button when count not finish.
  40. ;Case installer unload the plugins after this command
  41. Delay::Free
  42. FunctionEnd
复制代码


回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|手机版|Archiver|SgzyStudio

GMT+8, 2024-5-19 15:33 , Processed in 0.110921 second(s), 21 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表