Archive: button event plugin not working for more than one button in mui nsis


button event plugin not working for more than one button in mui nsis
  In GetButtonID function, when more than one button event handler is given ,then it autoexits before showing the Directory MUI page dialog.
But, when only one button event handler is given , then the Directory page is displayed without any problems.

!include "MUI2.nsh"

!define IDC_BUTTON_CDRIVEPATH 1200
!define IDC_BUTTON_DDRIVEPATH 1201

;---------------------------------------
;Name and file
Name Remove_ERROR
OutFile solve_error.exe
; -------------------------------

!define MUI_ICON "${NSISDIR}\Contrib\Graphics\Icons\setup.ico" ;
!define MUI_HEADERIMAGE
!define MUI_HEADERIMAGE_BITMAP "${NSISDIR}\Contrib\Graphics\Header\pksicon.bmp"
!define MUI_WELCOMEFINISHPAGE_BITMAP"${NSISDIR}\Contrib\Graphics\Wizard\img.bmp"
!define MUI_ABORTWARNING

!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_LICENSE "${NSISDIR}\Docs\Modern UI\licensefile.txt"

!define MUI_PAGE_CUSTOMFUNCTION_SHOW GetButtonID ;---in this function only one button event handler works, if two handlers are given , then installer crashes
!insertmacro MUI_PAGE_DIRECTORY

!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH
; --------------------------------------------------
; Languages.

!insertmacro MUI_LANGUAGE English


# Called when the CDRIVEPATH button is pressed.
Function CDRIVEPATH

MessageBox MB_OK|MB_ICONEXCLAMATION "The Software will be installed in : C Drive"

FunctionEnd

Function DDRIVEPATH

MessageBox MB_OK|MB_ICONEXCLAMATION "The Software will be installed in : D Drive"

FunctionEnd
;--------------------------------

Function GetButtonID
# Create event handler for inner window button.

GetFunctionAddress $R2 CDRIVEPATH
ButtonEvent::AddEventHandler ${IDC_BUTTON_CDRIVEPATH} $R2

;when this second button handler is given ,then installer autoexits as soon as it has to show the Directory MUI Page dialog:

GetFunctionAddress $R3 DDRIVEPATH
ButtonEvent::AddEventHandler ${IDC_BUTTON_DDRIVEPATH} $R3

FunctionEnd

;------------------------------------------------------------------
Section "INSTALL MAIN SOFTWARE"

SetOutPath $INSTDIR

File /r "myfolder\*.*"

SectionEnd
;------------------------------------------------------------------


I tried ButtonEvent plugin with two buttons on the same page and it works perfectly :)


Originally posted by T.Slappy
I tried ButtonEvent plugin with two buttons on the same page and it works perfectly :)
can you please tell me the code, i am adding the screenshot of the Directory MUI Dialog here: i think i have added it on outer or inner dialog am not sure? please helphttp://i.imgur.com/QnUKn.png

sir, can you please tell me the error in my code? its not working, when i press the I AGREE button on License page, then the installer exits, but when i remove the handler of the second button from the GETBUTTONID function, then it works properly.


Strange, your code is not working.
Plugin crashes on second ButtonEvent::AddEventHandler.
There is probably bug in the plugin - I will ask Afrow.

In my Graphical Installer I used exactly this code:

# Show Print button

>!ifdef GRAPHICAL_INSTALLER_PRINT_LICENSE
FindWindow$0 "#32770" "" $HWNDPARENT
GetDlgItem$0 $HWNDPARENT 2895
SendMessage$0 ${WM_SETTEXT} "STR:$(GraphicalInstallerButtonPrint)" 0
ShowWindow$0 ${SW_SHOW}

# Prepare function for printing license
GetFunctionAddress $R0 PrintLicenseFile
ButtonEvent
::AddEventHandler 2895 $R0
>!endif

># Show Save button
>!ifdef GRAPHICAL_INSTALLER_SAVE_LICENSE
FindWindow$0 "#32770" "" $HWNDPARENT
GetDlgItem$0 $HWNDPARENT 2896
SendMessage$0 ${WM_SETTEXT} "STR:$(GraphicalInstallerButtonSave)" 0
ShowWindow$0 ${SW_SHOW}

# Prepare function for saving license
GetFunctionAddress $R0 SaveLicenseFile
ButtonEvent::AddEventHandler 2896 $R0
>!endif
and everything was fine - both buttons worked at the same time.
One button was for printing license and second for saving license to hard disk - both on the same page License.

Are you using Unicode NSIS or not? Be sure not to mix the plug-ins either.

Stu


sir, how do i come to know whether am using Unicode NSIS or not? please help


If you downloaded NSIS from the NSIS website, then you have ANSI (non-Unicode) NSIS. The Unicode version is a special build. If you didn't explicitly look for it, you probably don't have it.


I am sure about this, it some king of bug.
I have non-Unicode version of NSIS and non-Unicode plugin and installers crashes.
But it crashes only in nsichildnew's script! - in my script (in reply #5) two buttons are working correctly!
So I assume that plugin is OK, but some other thing (maybe incorrect order of some lines in script, etc) prevents it from working correctly.

There is no time for me to debug it, but If you have some time try to debug script above by yourself.


I'll look into this bug later today.

Stu


Crash fixed, thanks.

http://nsis.sourceforge.net/File:ButtonEvent.zip

Stu


Stu, could you add event for other controls to your plug-in?
E.g.: I added Label [Static text] in UI.exe and I would like to attach onClick event to it.
Is is possible?


Sure it's possible but I would probably create a new plug-in that provides multiple event handlers. I will work on it when I have some free time.

Stu