Write NSIs script language Implementation Super button

Source: Internet
Author: User
Tags goto

Many development tools provide plug-ins to facilitate users to achieve some common functions, reduce the burden on programmers. Today's small knitting to tell you how to call the Buttonlinker plug-in implementation of the Super button effect.

/*

#脚本范例 #

Written: X-star, ZHFI

Description: Create Super button & link & menu with plugin and header file, do not need to modify UI

Resources: Plug-in "ButtonEvent.dll", "Linker.dll", "System.dll" and header file "Buttonlinkerlib.nsh"

*/

! 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 the own UI with custom buttons!

# The event handler for our parent button are 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"

/* Define the control to be created id*/

Note: ID cannot be duplicated, otherwise an unknown error will be generated!

; Define about buttons

!ifndef Idc_button

!define Idc_button 1190

!endif

; Define Links

!ifndef Idc_linker

!define Idc_linker 1200

!endif

; Define check boxes CheckBox2

!ifndef Idc_checkbox2

!define Idc_checkbox2 1210

!endif

; Define check boxes CheckBox3

!ifndef Idc_checkbox3

!define Idc_checkbox3 1220

!endif

; Definition about Menu 1

!ifndef IDM_ABOUT1

!define IDM_ABOUT1 1300

!endif

; Definition about Menu 2

!ifndef Idm_about2

!define Idm_about2 1301

!endif

; --------------------------------------------------

; Create a public function

!macro MyMacro UN

Function ${un}aboutbutton

MessageBox mb_ok| Mb_iconinformation "About the button!"

FunctionEnd

Function ${un}aboutmenu1

MessageBox mb_ok| Mb_iconinformation "about Menu 1!"

FunctionEnd

Function ${UN}ABOUTMENU2

MessageBox mb_ok| Mb_iconinformation "About Menu 2!"

FunctionEnd

Function ${un}checkbox3

/* Get control state/*

; Usage: ${getboxstate} output variable (0/1/error) parent window handle control ID

${getboxstate} $ $HWNDPARENT ${idc_checkbox3}

; MessageBox mb_ok| Mb_iconinformation "$"

${IF} $ = 0

MessageBox mb_yesno| Mb_iconinformation "deselect?" Idyes true Idno false

True

${setboxstate} 0 $HWNDPARENT ${idc_checkbox3}

Goto END

False

${setboxstate} 1 $HWNDPARENT ${idc_checkbox3}

Goto END

${elseif} $ = 1

MessageBox mb_yesno| Mb_iconinformation "Choice?" 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 $

Pop $

Pop $

Pop $

* * Create Super button

; Get the location of the Cancel button

${getdlgitemrect $ $ $ $HWNDPARENT ${idc_cancel}

Intop $ $-$

Usage: ${createbutton2} display text x axis position y axis position width height parent window handle Control ID target function

, refer to the "Cancel" location to create a super button

${createbutton2} "About (&a)" $ $HWNDPARENT ${idc_button} ${un}aboutbutton

/* Create Hyperlink/*

; Get the location of the Cancel button

${getdlgitemrect $ $ $ $HWNDPARENT ${idc_cancel}

Intop $ $-$

Intop $4

Intop $ $2-1

Usage: ${createlinker2} display text x axis position y axis position width height parent window handle control ID link address

; Refer to the location of "Cancel" to create a hyperlink

${CREATELINKER2} "Access to my home page" $ $HWNDPARENT ${idc_linker} "http://hi.baidu.com/xstar2008"

/* Create super check box * *

; Get the location of the Cancel button

${getdlgitemrect $ $ $ $HWNDPARENT ${idc_cancel}

Intop $ $-$

Intop $4

Intop $ $2-1

Usage: ${createcheckbox2} display text x axis position y axis position width height parent window handle Control ID control state (0/1)

, refer to the location of the Cancel to create the Super check box

${createcheckbox2} "CheckBox2" $ $HWNDPARENT ${idc_checkbox2} 1

Usage: ${createcheckbox3} display text x axis position y axis position width height parent window handle Control ID control state (0/1) objective function

, refer to the location of the Cancel to create the Super check box

${CREATECHECKBOX3} "CheckBox3" $ $HWNDPARENT ${idc_checkbox3} 0 ${un}checkbox3

/* Create Super Menu * *

Usage: ${createmenu2} display text menu type parent window handle Menu ID target function

${CREATEMENU2} 0 ${mf_separator} $HWNDPARENT 0 ${un}myguiinit

${CREATEMENU2} "About menu 1 (&a)" ${mf_string} $HWNDPARENT ${idm_about1} ${un}aboutmenu1

${CREATEMENU2} "About Menu 2 (&a)" ${mf_string} $HWNDPARENT ${idm_about2} ${un}aboutmenu2

FunctionEnd

Function ${un}.onguiend

Buttonevent::unload

Linker::unload

FunctionEnd

; --------------------------------------

!macroend

; Insert Install/unload function

!insertmacro MyMacro ""

!insertmacro MyMacro "un."

!insertmacro MyMacro "un"

section "Dummy" Secdummy

/* Get control state/*

; Usage: ${getboxstate} output variable (0/1/error) parent window handle control ID

${getboxstate} $ $HWNDPARENT ${idc_checkbox2}

STRCMP $1 0 +2

Messagebox MB_OK "What do you want?"

Sleep 1000

Writeuninstaller "$Exediruninst. exe"

Sectionend

Section Uninstall

Delete "$InstdirUninst. exe"

Sectionend

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.