這幾天準備系統性地學習一下NSIS腳本的編寫。函數
NSIS腳本中的MessageBox,語法以下:工具
MessageBox mb_option_list messagebox_text [/SD return] [return_check jumpto] [return_check_2 jumpto_2]
mb_option_list中列出了MessageBox的設定,有多個設定同時起做用時可用豎線(|)隔開,messagebox_text列出了MessageBox中正文部分顯示的文字,/SD表示靜默安裝時默認返回的結果,return_check、return_check_2列出了兩種不一樣的返回值,jumpto、jumpto_2分別列出了收到兩種不一樣返回值後應跳轉到的Goto語句標籤。學習
不一樣按鈕的返回值以下:測試
一、IDABORT - Abort button - 【停止】按鈕
code
二、IDCANCEL - Cancel button - 【取消】按鈕
orm
三、IDIGNORE - Ignore button - 【忽略】按鈕
ip
四、IDNO - No button - 【否】按鈕
it
五、IDOK - OK button - 【肯定】按鈕
io
六、IDRETRY - Retry button - 【重試】按鈕
編譯
七、IDYES - Yes button - 【是】按鈕
下面這段代碼,能夠當作一個模板:
!define DEBUG_PATH "E:\NSIS_Test\TmpProgram" !define OUTPUT_PATH "E:\NSIS_Test\Output" Name "NSIS_MessageBox_Test" Caption "NSIS_MessageBox_Test" Function .onInit ;TODO - 這裏輸入要測試的代碼 FunctionEnd OutFile "Galatea.exe" Section "My Program" SetOutPath ${OUTPUT_PATH} File /r "${DEBUG_PATH}\*.*" SectionEnd
我使用 HM NSIS Edit 2.0.3 工具編輯NSIS腳本,使用編譯工具 makensis.exe(版本號2.46) 進行編譯
本文中測試用的代碼都寫在.onInit函數中
就mb_option_list中的每一個屬性,我都寫了段代碼測試效果:
一、MB_OK - Display with an OK button
MessageBox只顯示一個肯定按鈕
Function .onInit ;這裏輸入要測試的代碼 MessageBox MB_OK "MB_OK - Display with an OK button" /SD IDOK IDOK label_ok label_ok: MessageBox MB_OK "你點擊了OK" FunctionEnd
二、MB_OKCANCEL - Display with an OK and a cancel button
MessageBox顯示肯定和取消兩個按鈕
Function .onInit ;這裏輸入要測試的代碼 MessageBox MB_OKCANCEL "MB_OKCANCEL - Display with an OK and a cancel button" \ /SD IDOK IDOK label_ok IDCANCEL label_cancel label_ok: MessageBox MB_OK "你點擊了OK" Goto end label_cancel: MessageBox MB_OK "你點擊了Cancel" Goto end end: FunctionEnd
三、MB_ABORTRETRYIGNORE - Display with abort, retry, ignore buttons
MessageBox顯示停止、重試和忽略三個按鈕
下面是一個錯誤的寫法:
Function .onInit ;這裏輸入要測試的代碼 MessageBox MB_ABORTRETRYIGNORE "MB_ABORTRETRYIGNORE - Display with abort, retry, ignore buttons" \ /SD IDABORT IDABORT label_abort IDRETRY label_retry IDIGNORE label_ignore label_abort: MessageBox MB_OK "你點擊了Abort" Goto end label_retry: MessageBox MB_OK "你點擊了Retry" Goto end label_ignore: MessageBox MB_OK "你點擊了Ignore" Goto end end: FunctionEnd
這個寫法的報錯信息以下:
Function: ".onInit" MessageBox expects 2-8 parameters, got 10. Usage: MessageBox mode messagebox_text [/SD return] _ [return_check label_to_goto_if_equal [return_check2 label2]] mode=modeflag[|modeflag[|modeflag[...]]] modeflag=(MB_ABORTRETRYIGNORE|MB_OK|MB_OKCANCEL|MB_RETRYCANCEL|MB_YESNO|MB_YESNOCANCEL _ |MB_ICONEXCLAMATION|MB_ICONINFORMATION|MB_ICONQUESTION|MB_ICONSTOP|MB_USERICON _ |MB_TOPMOST|MB_SETFOREGROUND|MB_RIGHT Error in script "E:\NSIS_Test\galatea.nsi" on line 7 -- aborting creation process
裏面說MessageBox只能有2-8個參數,在上面那段錯誤的代碼中咱們傳入了10個參數。解決這一問題的方法,就是少寫一個return_check條件。
Function .onInit ;這裏輸入要測試的代碼 MessageBox MB_ABORTRETRYIGNORE "MB_ABORTRETRYIGNORE - Display with abort, retry, ignore buttons" \ /SD IDABORT IDRETRY label_retry IDIGNORE label_ignore MessageBox MB_OK "你點擊了Abort" Goto end label_retry: MessageBox MB_OK "你點擊了Retry" Goto end label_ignore: MessageBox MB_OK "你點擊了Ignore" Goto end end: FunctionEnd
四、MB_RETRYCANCEL - Display with retry and cancel buttons
MessageBox顯示重試和取消兩個按鈕
Function .onInit ;這裏輸入要測試的代碼 MessageBox MB_RETRYCANCEL "MB_RETRYCANCEL - Display with retry and cancel buttons" \ /SD IDRETRY IDRETRY label_retry IDCANCEL label_cancel label_retry: MessageBox MB_OK "你點擊了Retry" Goto end label_cancel: MessageBox MB_OK "你點擊了Cancel" Goto end end: FunctionEnd
五、MB_YESNO - Display with yes and no buttons
MessageBox顯示是和否兩個按鈕
Function .onInit ;這裏輸入要測試的代碼 MessageBox MB_YESNO "MB_YESNO - Display with yes and no buttons" \ /SD IDYES IDYES label_yes IDNO label_no label_yes: MessageBox MB_OK "你點擊了Yes" Goto end label_no: MessageBox MB_OK "你點擊了No" Goto end end: FunctionEnd
六、MB_YESNOCANCEL - Display with yes, no, cancel buttons
MessageBox顯示是、否和取消三個按鈕
Function .onInit ;這裏輸入要測試的代碼 MessageBox MB_YESNOCANCEL "MB_YESNOCANCEL - Display with yes, no, cancel buttons" \ /SD IDYES IDNO label_no IDCANCEL label_cancel label_yes: MessageBox MB_OK "你點擊了Yes" Goto end label_no: MessageBox MB_OK "你點擊了No" Goto end label_cancel: MessageBox MB_OK "你點擊了Cancel" Goto end end: FunctionEnd
七、MB_ICONEXCLAMATION - Display with exclamation icon
MessageBox顯示警告標記,可與前面按鈕設置相關的功能選項共用
Function .onInit ;這裏輸入要測試的代碼 MessageBox MB_ICONEXCLAMATION "MB_ICONEXCLAMATION - Display with exclamation icon" \ /SD IDYES IDYes label_yes label_yes: MessageBox MB_OK "你點擊了Yes" FunctionEnd
八、MB_ICONINFORMATION - Display with information icon
MessageBox顯示信息標記,可與前面按鈕設置相關的功能選項共用
Function .onInit ;這裏輸入要測試的代碼 MessageBox MB_ICONINFORMATION "MB_ICONINFORMATION - Display with information icon" \ /SD IDYES IDYes label_yes label_yes: MessageBox MB_OK "你點擊了Yes" FunctionEnd
九、MB_ICONQUESTION - Display with question mark icon
MessageBox顯示詢問標記,可與前面按鈕設置相關的功能選項共用
Function .onInit ;這裏輸入要測試的代碼 MessageBox MB_YESNO|MB_ICONQUESTION "MB_ICONQUESTION - Display with question mark icon" \ /SD IDYES IDYES label_yes IDNO label_no label_yes: MessageBox MB_OK "你點擊了Yes" Goto end label_no: MessageBox MB_OK "你點擊了No" Goto end end: FunctionEnd
十、MB_ICONSTOP - Display with stop icon
MessageBox顯示禁止標記,可與前面按鈕設置相關的功能選項共用
Function .onInit ;這裏輸入要測試的代碼 MessageBox MB_ICONSTOP "MB_ICONSTOP - Display with stop icon" \ /SD IDYES IDYes label_yes label_yes: MessageBox MB_OK "你點擊了Yes" FunctionEnd
十一、MB_USERICON - Display with installer's icon
MessageBox顯示用戶定義圖標,可與前面按鈕設置相關的功能選項共用
Function .onInit ;這裏輸入要測試的代碼 MessageBox MB_USERICON "MB_USERICON - Display with installer's icon" \ /SD IDYES IDYes label_yes label_yes: MessageBox MB_OK "你點擊了Yes" FunctionEnd
十二、MB_TOPMOST - Make messagebox topmost
MessageBox提示窗置頂,可與前面的設置選項同時使用
Function .onInit ;這裏輸入要測試的代碼 MessageBox MB_YESNO|MB_TOPMOST "MB_TOPMOST - Make messagebox topmost" \ /SD IDYES IDYES label_yes IDNO label_no label_yes: MessageBox MB_OK "你點擊了Yes" Goto end label_no: MessageBox MB_OK "你點擊了No" Goto end end: FunctionEnd
1三、MB_SETFOREGROUND - Set foreground
設置MessageBox爲前景窗口
1四、MB_RIGHT - Right align text
設置MessageBox右對齊
Function .onInit ;這裏輸入要測試的代碼 MessageBox MB_YESNO|MB_RIGHT "MB_RIGHT - Right align text" \ /SD IDYES IDYES label_yes IDNO label_no label_yes: MessageBox MB_OK "你點擊了Yes" Goto end label_no: MessageBox MB_OK "你點擊了No" Goto end end: FunctionEnd
1五、MB_RTLREADING - RTL reading order
設置MessageBox閱讀順序爲自右向左,該模式下易致使界面顯示錯亂,故不推薦使用
Function .onInit ;這裏輸入要測試的代碼 MessageBox MB_YESNO|MB_RTLREADING "MB_RTLREADING - RTL reading order" \ /SD IDYES IDYES label_yes IDNO label_no label_yes: MessageBox MB_OK "你點擊了Yes" Goto end label_no: MessageBox MB_OK "你點擊了No" Goto end end: FunctionEnd
1六、MB_DEFBUTTON1 - Button 1 is default
1七、MB_DEFBUTTON2 - Button 2 is default
1八、MB_DEFBUTTON3 - Button 3 is default
1九、MB_DEFBUTTON4 - Button 4 is default
注:本文寫做過程當中參考了NSIS官方使用手冊 NSIS.chm
END