【问题标题】:fill directory textbox on button click in MUI NSI Installer , using ButtonEvent plug-in在 MUI NSI Installer 中单击按钮时填充目录文本框,使用 ButtonEvent 插件
【发布时间】:2011-04-27 11:18:51
【问题描述】:

我已经在安装程序的 MUI 目录页面上使用 Resource Hacker 添加了自定义按钮,现在我希望当单击该按钮时,用户输入 InstallDir(安装应用程序的路径)的默认文本框是填充一些指定的文本。请帮我写代码?

我正在使用 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

------------新编辑部分--三个自定义按钮的代码---------- ---------

!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

【问题讨论】:

    标签: button installation custom-controls nsis modern-ui


    【解决方案1】:

    你没有说你使用的是哪个版本的 MUI,这个宏应该同时处理这两个...

    !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
    
    
    ;In buttonclicked handler
    !insertmacro SetDirPageInstallDir "$programfiles\Hello World"
    

    【讨论】:

    • 非常感谢先生,但是当我使用 2 或 3 个自定义按钮时,当我运行安装程序时,当必须出现自定义按钮所在的对话框页面时,它会自动退出。我已经在我帖子的编辑部分发布了新代码
    • @sqlchild:我从来没有使用过那个插件,但是在 myGuiInit 和 DirectoryShow 中添加按钮对我来说并不合适。要获取更多信息,您应该询问 nsis 论坛上的插件作者或 wiki 上的插件讨论页...
    • 好的先生,这是一个ButtonEvent插件的问题吗?当我的对话框上只有一个自定义按钮并且正在使用 ButtonEvent 插件时,您的代码可以成功运行,那么它可以正常工作。
    • 所以,这个问题是插件的问题,所以我要问作者,告诉我代码,为多个按钮添加按钮事件?不是吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-16
    • 1970-01-01
    相关资源
    最近更新 更多