很多开发工具中都提供了插件方便用户实现一些常见的功能,减少程序员的负担。今天小编就来跟大家介绍如何调用Buttonlinker插件实现超级按钮效果。
!AddPluginDir "."
!AddIncludeDir "."
!include MUI2.nsh
!include ButtonlinkerLib.nsh
;!include UsefulLib.nsh
; --------------------------------------------------
; General settings.
Name "Buttonlinker Example"
OutFile "ButtonlinkerMUI.exe"
SetCompressor /SOLID lzma
;ReserveFile "Buttonlinker.dll"
; --------------------------------------------------
; MUI interface settings.
# We want to use our own UI with custom buttons!
# The event handler for our parent button is added in MyGUIInit.
!define MUI_CUSTOMFUNCTION_GUIINIT MyGUIInit
# Don't skip to the finish page.
!define MUI_FINISHPAGE_NOAUTOCLOSE
; --------------------------------------------------
; Insert MUI pages.
; Installer pages
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_LICENSE Buttonlinker.nsi
!insertmacro MUI_PAGE_INSTFILES
; UnInstaller pages
!define MUI_CUSTOMFUNCTION_UnGUIINIT Un.MyGUIInit
!insertmacro MUI_UnPAGE_WELCOME
!insertmacro MUI_UnPAGE_INSTFILES
; --------------------------------------------------
; Languages.
!insertmacro MUI_LANGUAGE "SimpChinese"
;注意:ID不能重复,否则会产生未知错误!
;定义关于按钮
!ifndef IDC_BUTTON
!define IDC_BUTTON 1190
!endif
;定义链接
!ifndef IDC_linkER
!define IDC_linkER 1200
!endif
;定义复选框CheckBox2
!ifndef IDC_CheckBox2
!define IDC_CheckBox2 1210
!endif
;定义复选框CheckBox3
!ifndef IDC_CheckBox3
!define IDC_CheckBox3 1220
!endif
;定义关于菜单1
!ifndef IDM_about1
!define IDM_about1 1300
!endif
;定义关于菜单2
!ifndef IDM_about2
!define IDM_about2 1301
!endif
; --------------------------------------------------
; 创建公共函数
!macro MYMACRO un
Function ${un}aboutButton
MessageBox MB_OK|MB_IConINFORMATION "关于按钮!"
FunctionEnd
Function ${un}aboutMenu1
MessageBox MB_OK|MB_IConINFORMATION "关于菜单1!"
FunctionEnd
Function ${un}aboutMenu2
MessageBox MB_OK|MB_IConINFORMATION "关于菜单2!"
FunctionEnd
Function ${un}CheckBox3
;用法:${GetBoxState} 输出变量(0/1/error) 父窗口窗口句柄 控件ID
${GetBoxState} $0 $HWNDPARENT ${IDC_CheckBox3}
; MessageBox MB_OK|MB_IConINFORMATION "$0"
${if} $0 == 0
MessageBox MB_yesno|MB_IConINFORMATION "取消选择?" idyes true idno false
true:
${SetBoxState} 0 $HWNDPARENT ${IDC_CheckBox3}
goto End
false:
${SetBoxState} 1 $HWNDPARENT ${IDC_CheckBox3}
goto End
${elseif} $0 == 1
MessageBox MB_yesno|MB_IConINFORMATION "选择?" idyes true2 idno false2
true2:
${SetBoxState} 1 $HWNDPARENT ${IDC_CheckBox3}
goto End
false2:
${SetBoxState} 0 $HWNDPARENT ${IDC_CheckBox3}
goto End
${else}
MessageBox MB_OK|MB_IConINFORMATION "$0!"
${endif}
End:
FunctionEnd
Function ${un}MyGUIInit
InitPluginsDir
Pop $0
Pop $1
Pop $2
Pop $3
;获取“取消”按钮的位置
${GetDlgItemRect} $0 $1 $2 $3 $HWNDPARENT ${IDC_CANCEL}
IntOp $2 $3 - $1
;用法:${CreateButton2} 显示文本 X轴位置 Y轴位置 宽度 高度 父窗口窗口句柄 控件ID 目标函数
;参考“取消”的位置来创建超级按钮
${CreateButton2} "关于(&A)" 20 $1 80 $2 $HWNDPARENT ${IDC_BUTTON} ${un}aboutButton
;获取“取消”按钮的位置
${GetDlgItemRect} $0 $1 $2 $3 $HWNDPARENT ${IDC_CANCEL}
IntOp $2 $3 - $1
IntOp $1 $1 + 4
IntOp $2 $2 - 1
;用法:${Createlinker2} 显示文本 X轴位置 Y轴位置 宽度 高度 父窗口窗口句柄 控件ID 链接地址
;参考“取消”的位置来创建超级链接
${Createlinker2} "访问我的主页" 120 $1 80 $2 $HWNDPARENT ${IDC_linkER} "http://hi.baidu.com/xstar2008"
;获取“取消”按钮的位置
${GetDlgItemRect} $0 $1 $2 $3 $HWNDPARENT ${IDC_CANCEL}
IntOp $2 $3 - $1
IntOp $1 $1 + 4
IntOp $2 $2 - 1
;用法:${CreateCheckBox2} 显示文本 X轴位置 Y轴位置 宽度 高度 父窗口窗口句柄 控件ID 控件状态(0/1)
;参考“取消”的位置来创建超级复选框
${CreateCheckBox2} "CheckBox2" 200 $1 50 $2 $HWNDPARENT ${IDC_CheckBox2} 1
;用法:${CreateCheckBox3} 显示文本 X轴位置 Y轴位置 宽度 高度 父窗口窗口句柄 控件ID 控件状态(0/1) 目标函数
;参考“取消”的位置来创建超级复选框
${CreateCheckBox3} "CheckBox3" 250 $1 50 $2 $HWNDPARENT ${IDC_CheckBox3} 0 ${un}CheckBox3
;用法:${CreateMenu2} 显示文本 菜单类型 父窗口窗口句柄 菜单ID 目标函数
${CreateMenu2} 0 ${MF_SEPARATOR} $HWNDPARENT 0 ${un}MyGUIInit
${CreateMenu2} "关于菜单1(&A)" ${MF_STRING} $HWNDPARENT ${IDM_about1} ${un}aboutMenu1
${CreateMenu2} "关于菜单2(&A)" ${MF_STRING} $HWNDPARENT ${IDM_about2} ${un}aboutMenu2
FunctionEnd
Function ${un}.onGUIEnd
ButtonEvent::unload
linker::unload
FunctionEnd
; --------------------------------------
!macroend
; 插入安装/卸载函数
!insertmacro MYMACRO ""
!insertmacro MYMACRO "un."
!insertmacro MYMACRO "un"
Section "Dummy" SecDummy
;用法:${GetBoxState} 输出变量(0/1/error) 父窗口窗口句柄 控件ID
${GetBoxState} $0 $HWNDPARENT ${IDC_CheckBox2}
StrCmp $0 1 0 +2
Messagebox MB_OK "你想干嘛?"
Sleep 1000
WriteUninstaller "$Exediruninst.exe"
SectionEnd
Section Uninstall
Delete "$InstdirUninst.exe"
SectionEnd