Extra buttons, go Next

Anonymous user
Extra buttons, go Next

Hi,
first, thanks for developing this great app.

I cannot find the way to read which button was pressed, based on that make an action, and then continue with the next page.

Var action
 
!include "resources\already_installed.nsdinc"
 
Page Custom PrePage
 
Function PrePage   
    ReadRegStr $R0 HKLM "${PRODUCT_UNINST_KEY}" "UninstallString"
    StrCmp $R0 "" NotInstalled
        Call fnc_already_installed_Show
NotInstalled:
 
FunctionEnd
 
Function reinstall_click
    StrCpy $action 1
    Call PreLeave
FunctionEnd
 
Function uninstall_click
    StrCpy $action 2
    Call PreLeave
FunctionEnd
 
Function cancel_1_click
    StrCpy $action 3
    Call PreLeave
FunctionEnd
 
Function PreLeave
    StrCmp $action 0 cancel
    StrCmp $action 1 reinstall
    StrCmp $action 2 unistall
    StrCmp $action 3 cancel
unistall:
    Exec $INSTDIR\uninst.exe
cancel:
    Quit
reinstall:
FunctionEnd
 
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_LICENSE "License.rtf"
!insertmacro MUI_PAGE_INSTFILES
!define MUI_FINISHPAGE_RUN "$INSTDIR\Program123.exe"
!insertmacro MUI_PAGE_FINISH

And the code from NSISDialogDesigner is:

; handle variables
Var hCtl_already_installed    
Var hCtl_already_installed_Label1    
Var hCtl_already_installed_Label3    
Var hCtl_already_installed_Button1    
Var hCtl_already_installed_Button3    
Var hCtl_already_installed_Label2    
Var hCtl_already_installed_Button2
 
; dialog create function
Function fnc_already_installed_Create
 
  ; === already_installed (type: Dialog) ===
  nsDialogs::Create 1018
 
  Pop $hCtl_already_installed
 
  ${If} $hCtl_already_installed == error
    Abort
  ${EndIf}
 
  !insertmacro MUI_HEADER_TEXT "$(ALREADY_INSTALLED_HEADER)" "$(ALREADY_INSTALLED_TEXT)"
 
  ; === Label1 (type: Label) ===
  ${NSD_CreateLabel} 127u 7u 143u 32u "$(REINSTALL_TEXT)"
  Pop $hCtl_already_installed_Label1
 
  ; === Label3 (type: Label) ===
  ${NSD_CreateLabel} 127u 47u 143u 32u "$(UNINSTALL_TEXT)"
  Pop $hCtl_already_installed_Label3
 
  ; === Button1 (type: Button) ===
  ${NSD_CreateButton} 18u 7u 97u 32u "$(REINSTALL_BTN)"
  Pop $hCtl_already_installed_Button1
  ${NSD_OnClick} $hCtl_already_installed_Button1 reinstall_click
 
  ; === Button3 (type: Button) ===
  ${NSD_CreateButton} 18u 47u 97u 32u "$(UNINSTALL_BTN)"
  Pop $hCtl_already_installed_Button3
  ${NSD_OnClick} $hCtl_already_installed_Button3 uninstall_click
 
  ; === Label2 (type: Label) ===
  ${NSD_CreateLabel} 127u 89u 143u 32u "$(CANCEL_TEXT)"
  Pop $hCtl_already_installed_Label2
 
  ; === Button2 (type: Button) ===
  ${NSD_CreateButton} 18u 89u 97u 32u "$(CANCEL_BTN)"
  Pop $hCtl_already_installed_Button2
  ${NSD_OnClick} $hCtl_already_installed_Button2 cancel_click
 
FunctionEnd
 
; dialog show function
Function fnc_already_installed_Show
  Call fnc_already_installed_Create
  nsDialogs::Show $hCtl_already_installed
FunctionEnd

But the problem is that the buttons do not respond.
They do the function, but then it doesn’t continue.

Can you help me with that?

Thanks a lot
Maria

Posts: 1121
Joined: March 25, 2012 - 01:19
You're breaking the natural

You're breaking the natural script workflow, mixing xxxPage and xxxLeave functions.

Here's a working script, based on yours:

; MUI Symbol Definitions
!include Sections.nsh
!include MUI2.nsh
!insertmacro MUI_LANGUAGE English
 
OutFile test.exe
Var action
 
!insertmacro MUI_PAGE_WELCOME
Page custom PrePage PreLeave
!insertmacro MUI_PAGE_FINISH
 
Section main
SectionEnd
 
Function PrePage   
    Call fnc_already_installed_Show
FunctionEnd
 
Function reinstall_click
    StrCpy $action 1
    Call GotoNextPage
FunctionEnd
 
Function uninstall_click
    StrCpy $action 2
    Call GotoNextPage
FunctionEnd
 
Function cancel_click
    StrCpy $action 3
    Call GotoNextPage
FunctionEnd
 
Function PreLeave
    StrCmp $action 0 cancel
    StrCmp $action 1 reinstall
    StrCmp $action 2 unistall
    StrCmp $action 3 cancel
unistall:
    MessageBox MB_OK "uninstall"
    Quit
cancel:
    MessageBox MB_OK "cancel"
    Quit
reinstall:
    MessageBox MB_OK "reinstall"
    Quit
FunctionEnd
 
Function GotoNextPage
  SendMessage $HWNDPARENT "0x408" "1" ""
FunctionEnd
 
; handle variables
Var hCtl_already_installed    
Var hCtl_already_installed_Label1    
Var hCtl_already_installed_Label3    
Var hCtl_already_installed_Button1    
Var hCtl_already_installed_Button3    
Var hCtl_already_installed_Label2    
Var hCtl_already_installed_Button2
 
; dialog create function
Function fnc_already_installed_Create
 
  ; === already_installed (type: Dialog) ===
  nsDialogs::Create 1018
 
  Pop $hCtl_already_installed
 
  ${If} $hCtl_already_installed == error
    Abort
  ${EndIf}
 
  !insertmacro MUI_HEADER_TEXT "ALREADY_INSTALLED_HEADER" "ALREADY_INSTALLED_TEXT"
 
  ; === Label1 (type: Label) ===
  ${NSD_CreateLabel} 127u 7u 143u 32u "REINSTALL_TEXT"
  Pop $hCtl_already_installed_Label1
 
  ; === Label3 (type: Label) ===
  ${NSD_CreateLabel} 127u 47u 143u 32u "UNINSTALL_TEXT"
  Pop $hCtl_already_installed_Label3
 
  ; === Button1 (type: Button) ===
  ${NSD_CreateButton} 18u 7u 97u 32u "REINSTALL_BTN"
  Pop $hCtl_already_installed_Button1
  ${NSD_OnClick} $hCtl_already_installed_Button1 reinstall_click
 
  ; === Button3 (type: Button) ===
  ${NSD_CreateButton} 18u 47u 97u 32u "UNINSTALL_BTN"
  Pop $hCtl_already_installed_Button3
  ${NSD_OnClick} $hCtl_already_installed_Button3 uninstall_click
 
  ; === Label2 (type: Label) ===
  ${NSD_CreateLabel} 127u 89u 143u 32u "CANCEL_TEXT"
  Pop $hCtl_already_installed_Label2
 
  ; === Button2 (type: Button) ===
  ${NSD_CreateButton} 18u 89u 97u 32u "CANCEL_BTN"
  Pop $hCtl_already_installed_Button2
  ${NSD_OnClick} $hCtl_already_installed_Button2 cancel_click
 
FunctionEnd
 
; dialog show function
Function fnc_already_installed_Show
  Call fnc_already_installed_Create
  nsDialogs::Show $hCtl_already_installed
FunctionEnd

What I changed:

  1. Custom page now defines both pre and leave function:
    Page custom PrePage PreLeave
  2. PrePage function, and button callbacks, will only set $action variable value, then ask installer to proceed to the next page calling then new GotoNextPage function (see here for details).
    PrePage function and its subfunctions now won't change script workflow.
  3. PreLeave function is called by NSIS when leaving the page (asyncronously after GotoNextPage call), so its content can be executed (and also Quit works).
warning

Warning, JavaScript is disabled!

JavaScript is not available, maybe because you disabled it globally into your browser settings or you are using an addon like NoScript.

We do not have any dangerous JavaScript running here.
Please enable JavaScript; if you're using NoScript this image will help you adding CoolSoft to your whitelist.

Thanks for your comprehension and enjoy CoolSoft.