編寫NSIS指令碼語言實現常用鍵

來源:互聯網
上載者:User

編寫NSIS指令碼語言實現常用鍵

   很多開發工具中都提供了外掛程式方便使用者實現一些常見的功能,減少程式員的負擔。今天小編就來跟大家介紹如何調用ButtonLinker外掛程式實現常用鍵效果。

  /*

  #指令碼範例#

  編寫:X-Star, zhfi

  描述:利用外掛程式與標頭檔建立常用鍵&連結&菜單,無需修改UI即可實現

  資源:外掛程式 "ButtonEvent.dll"、"linker.dll"、"System.dll" 及標頭檔 "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 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*/

  ;注意: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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.