0
我已經在安裝程序的MUI目錄頁面上添加了使用Resource Hacker的自定義按鈕,現在我希望當按鈕被單擊時默認文本框在哪裏用戶輸入InstallDir(安裝應用程序的路徑),填充一些指定的文本。請幫助我的代碼?在按鈕上填充目錄文本框在MUI NSI安裝程序中單擊使用ButtonEvent插件
我正在使用ButtonEvent插件,但我不知道在事件處理程序中寫什麼代碼。目前我只是在點擊按鈕時顯示一個消息框,以確保事件正常。 請幫忙。
!define IDC_BUTTON_SETPATH 1200 (1200 is the ID OF THE BUTTON ADDED from Resource hacker)
;Pages
!insertmacro MUI_PAGE_WELCOME
!define MUI_PAGE_CUSTOMFUNCTION_SHOW DirectoryShow
!define MUI_PAGE_CUSTOMFUNCTION_LEAVE DirectoryLeave
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH
;--------------------------------
Function buttonclicked
MessageBox MB_OK|MB_ICONEXCLAMATION "You Clicked Me "
Abort
FunctionEnd
# Occurs on installer UI initialization.
Function myGuiInit
# Create event handler for our parent window button.
GetFunctionAddress $R3 buttonclicked
ButtonEvent::AddEventHandler ${IDC_BUTTON_SETPATH} $R3
FunctionEnd
------------------------編輯後的新PART-- CODE FOR THREE自定義按鈕-------- -----------
!include MUI2.nsh
; --------------------------------------------------
!define IDC_BUTTON_CDRIVEPATH 1200
!define IDC_BUTTON_DDRIVEPATH 1201
!define IDC_BUTTON_EDRIVEPATH 1202
; --------------------------------------------------
# The event handler for our parent button is added in MyGUIInit.
!define MUI_CUSTOMFUNCTION_GUIINIT myGuiInit
!define MUI_HEADERIMAGE
!define MUI_HEADERIMAGE_BITMAP "${NSISDIR}\Contrib\Graphics\Header\pksicon.bmp" ; optional
!define MUI_WELCOMEFINISHPAGE_BITMAP "${NSISDIR}\Contrib\Graphics\Wizard\pksleftimage.bmp" ;
;--------------------------------
XPStyle on
;Interface Settings
!define MUI_ABORTWARNING
;--------------------------------
;Pages
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_LICENSE "${NSISDIR}\Docs\Modern UI\licensefile.txt"
!define MUI_PAGE_CUSTOMFUNCTION_SHOW DirectoryShow
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH
; --------------------------------------------------
; Languages.
!insertmacro MUI_LANGUAGE English
; --------------------------------------------------
!macro SetDirPageInstallDir text
!if "${MUI_SYSVERSION}" < "2.0"
Push $0
FindWindow $0 "#32770" "" $HWNDPARENT
GetDlgItem $0 $0 0x3FB
SendMessage $0 ${WM_SETTEXT} 0 "STR:${text}"
Pop $0
!else
SendMessage $mui.DirectoryPage.Directory ${WM_SETTEXT} 0 "STR:${text}"
!endif
!macroend
# Called when the CDRIVEPATH button is pressed.
Function CDRIVEPATH
MessageBox MB_OK|MB_ICONEXCLAMATION "The Software will be installed in : C:\ "
;In buttonclicked handler
!insertmacro SetDirPageInstallDir "C:\"
FunctionEnd
;--------------------------------
Function DDRIVEPATH
MessageBox MB_OK|MB_ICONEXCLAMATION "The Software will be installed in : D:\ "
;In buttonclicked handler
!insertmacro SetDirPageInstallDir "D:\"
FunctionEnd
;--------------------------------
Function EDRIVEPATH
MessageBox MB_OK|MB_ICONEXCLAMATION "The Software will be installed in : E:\ "
;In buttonclicked handler
!insertmacro SetDirPageInstallDir "E:\"
FunctionEnd
;--------------------------------
InstallDir $INSTDIR
# Occurs on installer UI initialization.
Function myGuiInit
# Create event handler for our parent window button.
GetFunctionAddress $R0 CDRIVEPATH
ButtonEvent::AddEventHandler ${IDC_BUTTON_CDRIVEPATH} $R0
; GetFunctionAddress $R1 EDRIVEPATH **-----this line causes error**
; ButtonEvent::AddEventHandler ${IDC_BUTTON_DDRIVEPATH} $R1 -----this line causes error
; GetFunctionAddress $R2 EDRIVEPATH **-----this line causes error**
; ButtonEvent::AddEventHandler ${IDC_BUTTON_EDRIVEPATH} $R2 -----this line causes error
FunctionEnd
;------------------------------------------------
# Occurs on Directory page show.
Function DirectoryShow
# Create event handler for our Directory page button. /NOTIFY makes
# the button move to the next page when clicked.
ButtonEvent::AddEventHandler ${IDC_BUTTON_CDRIVEPATH}
ButtonEvent::AddEventHandler ${IDC_BUTTON_DDRIVEPATH}
ButtonEvent::AddEventHandler ${IDC_BUTTON_EDRIVEPATH}
# Disable next button.
GetDlgItem $R0 $HWNDPARENT 1
EnableWindow $R0 0
FunctionEnd
; --------------------------------------------------
;General
;Name and file
Name NEW_FILL_TEXTBOX_BUTTONCLICK
OutFile NEW_FILL_TEXTBOX_BUTTONCLICK.exe
Section
DetailPrint "SUCCESSFULLY INSTALLED"
SectionEnd
非常感謝先生,但是當我使用2或3個自定義按鈕時,當我運行安裝程序時,它會自動退出,其中的對話框頁面自定義按鈕不得不出現。我已經在我的帖子的編輯部分發布了新代碼 – sqlchild 2011-04-28 09:53:09
@sqlchild:我從來沒有使用過這個插件,但是在myGuiInit和DirectoryShow中添加按鈕並不適合我。要獲得更多的信息,你應該問在nsis論壇上的插件作者或維基上的插件談話頁面... – Anders 2011-04-28 11:11:30
好的SIR,所以這是一個ButtonEvent插件的問題?你的代碼工作成功時,我只有一個單一的定製按鈕,我的對話框,並使用ButtonEvent插件,那麼它工作正常。 – sqlchild 2011-04-28 11:48:50