NSIS 简易教程(三)


;回调函数有特定的名字,在特定的时间调用
  ;目前可用的callback functions:
  1.    .onGUIInit
  ;this callback will be called just before the first page is loaded and the installer dialog is shown
  ; allowing you to tweak(调整) the user interface
  !include "WinMessages.nsh"
  Function .onGUIInit
  GetDlgItem $R0 $HWNDPARENT 1028
  CreateFont $R1 "Tahoma" 10 700
  SendMessage $R0 ${WM_SETFONT} $R1 0
  #set background color to white and text color to red
  SetCtlColors $R0 FFFFFF FF0000
  FunctionEnd
  2.    .onInit;即将完成初始化
  ;this function will be called when the installer is nearly finished initializing. if the '.onInit' function
  ; calls abort,the installer will quit instantly.
  Function .onInit
  MessageBox MB_YESNO "This will install .Continue?" IDYES NoAbort
  Abort;causes installer to quit.
  FunctionEnd
  3.    .onInstFailed;安装失败时点击取消
  ;this callback is called when the user hits the 'cancel' button after the install has failed
  Function .onInstFailed
  MessageBox MB_OK "Better luck next time."
  FunctionEnd
  4.    .onInstSuccess ;安装成功窗口关闭前
  ;this callback is called when the install was successful,right before the install window closes(which
  ;may be after the user clicks 'Close' if AutoCloseWindow or SetAutoClose is set to false)
  Function .onInstSuccess
  MessageBox MB_YESNO "Congrats,it worked.View readme?" IDNO NoReadme
  Exec notepad.exe;view readme or whatever if you want.
  NoReadme:
  FunctionEnd
  5.    .onGUIEnd;;安装成功窗口关闭后
  ;this callback is called right after the installer window closes.Use it to free any user interface
  ;related plug-ins if needed
  6.    .onMouseOverSection;鼠标放置的session发生变化是被调用,可以用于改变描述信息
  ;this callback is called whenever the mouse position over the sections tree has changed.this allows
  ;you to set a description for each section for example.this section id on which the mouse is over
  ;currently is stored ,temporarily,in $0
  Function .onMouseOverSection
  FindWindow $R0 "#32770" "" $HWNDPARENT
  GetDlgItem $R0 $R0 1043
  StrCmp $0 0 "" +2
  SendMessage $R0 ${WM_SETTEXT} 0 "STR:first section description"
  StrCmp $0 1 "" +2
  SendMessage $R0 ${WM_SETTEXT} 0 "STR:second section description"
  FunctionEnd
  7.    onRebootFailed;自动重启失败
  ;this callback is called if Reboot fails.WritUninstaller,plug-ins,File and WriteRegBin should not be used
  ;in this callback
  Function .onRebootFailed
  MessageBox MB_OK|MB_ICONSTOP "Reboot failed,Please reboot manually." /SD IDOK
  FunctionEnd
  8.    onSelChange;选择发生变化
  ;called when the selection changes on the component page.Usefull for using with SectionSetFlags and
  ;SectionSetFlags and SectionGetFlags.
  ;selection changes include both section selection and installation type change.
  9.    onUserAbort
  ;安装还没有失败但用户选择了取消时调用,调用Abort时,程序不会退出
  ;called when the user hits the 'cancel' button,and the install hasn't already failed.If this function
  ;calls Abort,the install will not be aborted.
  Function
  MessageBox MB_YESNO "Abort install?" IDYES NoCancelAbort
  Abort;
  NoCancelAbort:
  do something
  FunctionEnd
  10.    .onVerifyInstDir
  ;在安装文件夹改变后调用,检查该路径是否有效,如果调用了Abort则$INSTDIR视为无效
  ;enables control over whether or not an installation path is valid for your installer. This code will be
  ;called every time the user changes the install directory,so it shouldn't do anything crazy with MessageBox
  ;or the likes.If this function calls Abort,the installation path in $INSTDIR is deemed invalid.
  Function
  IfFileExists $INSTDIR\Winamp.exe PathGood
  Abort
  PathGood:
  FunctionEnd
  Uninstall Callbacks
  11.    un.onGUIInit;卸载程序的类似于.onGUIInit
  ;called just before the first page is loaded and the installer dialog is shown, allowing you to tweak the
  ;user interface.
  12.    un.onInit;若调用了Abort,程序直接退出,在有必要时检查一下$INSTDIR
  ;this callback will be called when the uninstaller is nearly finished initializeing.If the
  ;'un.onInit' function calls Abort,the uninstaller will quit instantly.Note that this function can verify
  ;and/or modify $INSTDIR if necessary.
  Function un.onInit
  MessageBox MB_YESNO "This will uninstall." IDYES NoAbort
  Abort
  NoAbort:
  FunctionEnd
  Function un.onInit
  IfFileExists $INSTDIR\myfile.exe found
  MessageBox MB_OK "Uninstall path incorrent"
  Abort
  found:
  FunctionEnd
  13.    un.onUninstFailed
  ;called when the user hits the 'cancel' button after the uninstall has failed(if it used the 
  ;Abort command or otherwise failed).
  14.    un.onUninstSuccess
  15.    un.onGUIEnd
  16.    un.onRebootFailed
  17.    un.onSelChange
  18.    un.onUserAbort
  Installer Attributes
  these attributes control how the installer looks and functions,including which pages are present in the
  installer ,as what text is displayed in each part of each page,how the installer is named,what icon the
  installer uses,the default installation directory,what file it writes out,and more,note that these attributes
  can be set anywhere in the file except in a Section or Function .
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
NSIS(Nullsoft Scriptable Install System)是一款免费且开源的安装制作工具,能够帮助开发者创建Windows安装程序。下面是关于NSIS的图文教程集锦: 1. 下载和安装NSIS:首先需要从NSIS官方网站上下载NSIS的安装包,并按照提示完成安装过程。 2. 创建一个NSIS脚本:使用任意文本编辑器创建一个以.nsi为扩展名的文件,这个文件就是NSIS的脚本文件。在脚本文件中可以定义安装程序的界面、文件的安装位置等。 3. 定义安装界面:NSIS提供了丰富的选项和命令来定义安装界面。你可以添加文本、图标、按钮等元素,以及自定义其位置和样式。 4. 添加文件:使用NSIS的File命令将要安装的文件添加进安装程序中。你可以指定文件的来源路径、目标路径等。 5. 设定安装选项:NSIS的配置命令可以帮助你定义一些安装选项,比如安装路径、创建快捷方式、注册表项等。 6. 定义卸载功能:使用Uninstall命令可以创建卸载程序,方便用户在需要时卸载安装的软件。 7. 编译和测试:完成脚本文件后,使用NSIS提供的编译器将脚本文件编译成可执行的安装程序。然后进行测试,确保安装程序的功能和界面都符合预期。 8. 发布安装程序:将编译好的安装程序发布出去,用户可以下载并安装你的软件。 总结:NSIS是一款功能强大的安装制作工具,通过上述简单的图文教程,你可以学会如何使用NSIS创建自定义的Windows安装程序。这些教程将帮助你快速上手NSIS,并使你的软件安装过程更加专业和用户友好。祝你制作出优秀的安装程序!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值