Skip to content
⌘ NSIS Forum Archive

enable/disable "Next" button with checkbox

2 posts

Marcus1807#

enable/disable "Next" button with checkbox

Hello,

I've written some code to disable and enable the "Next" Button on a custom page:
; Welcome page
!insertmacro MUI_PAGE_WELCOME
;Custum Function
Page custom showCheckSummary leaveCheckSummary
; License page
!define MUI_LICENSEPAGE_CHECKBOX
!insertmacro MUI_PAGE_LICENSE "Prototype.txt"
; Directory page
!insertmacro MUI_PAGE_DIRECTORY
; Instfiles page
!insertmacro MUI_PAGE_INSTFILES
; Finish page
!insertmacro MUI_PAGE_FINISH
; Uninstaller pages
!insertmacro MUI_UNPAGE_INSTFILES
; Language files
!insertmacro MUI_LANGUAGE "English"
!insertmacro MUI_LANGUAGE "German"
; MUI end ------
Name "${PRODUCT_NAME}"
OutFile "Setup_ADEPAut.exe"
VAR INI_VALUE
VAR ERROR_MESSAGE
VAR hwnd
Function showCheckSummary
 !insertmacro MUI_INSTALLOPTIONS_WRITE "checkSummary.ini" "FIELD 3" "State" "0"
  GetDlgItem $hwnd $HWNDPARENT 1 ;AUSKOMMENTIEREN WENN FUNCTION MIT MSGBOX
  EnableWindow $hwnd 0           ;AUSKOMMENTIEREN WENN FUNCTION MIT MSGBOX
  ;Write values into Textfield
 !insertmacro MUI_INSTALLOPTIONS_WRITE "checkSummary.ini" "FIELD 2" "State" "$ERROR_MESSAGE"
 !insertmacro MUI_HEADER_TEXT "Summary" ""
 !insertmacro MUI_INSTALLOPTIONS_DISPLAY "checkSummary.ini"
 
 ;!insertmacro MUI_INSTALLOPTIONS_READ $INI_VALUE "checkSummary.ini" "FIELD 3" "STATE"
 ;strcmp $INI_VALUE 1
 
FunctionEnd
Function leaveCheckSummary
 !insertmacro MUI_INSTALLOPTIONS_READ $INI_VALUE "checkSummary.ini" "FIELD 3" "STATE"
  StrCmp $INI_VALUE 3 clicked notClicked
  notClicked:
   GetDlgItem $hwnd $HWNDPARENT 1 
   EnableWindow $hwnd 0
   Abort ; Return to the page
  clicked:
   GetDlgItem $hwnd $HWNDPARENT 1
   EnableWindow $hwnd 1
FunctionEnd
    
Function .onInit
  ; Extract InstallOptions files
  ; $PLUGINSDIR will automatically be removed when the installer closes
  InitPluginsDir
  File /oname=$PLUGINSDIR\test.ini "checkSummary.ini"
 strcpy $9 "false"
 !insertmacro MUI_LANGDLL_DISPLAY
 ;Check Version-Number
 call CheckADVersion
 
 ;Read InstallDir
 call GetInstallDir
 StrCpy $INSTDIR "$R0"
 StrCpy $INSTDIR "$INSTDIR..."
 
 ;Check Version-Number
 call CheckVersion
 ;CheckWindow
 strcmp $9 "true" equal notEqual
 equal:
  !insertmacro MUI_INSTALLOPTIONS_EXTRACT "checkSummary.ini"
 notEqual:
FunctionEnd 
and here is my checkSummary.ini-File:

[Settings]
NumFields=3
State=0
[Field 1]
Type=label
Text=Following Errors were found: 
Left=0
Right=-1
Top=0
Bottom=10
[Field 2]
Type=text
Left=0
Right=-1
Top=20
Bottom=100
flags=MULTILINE|VSCROLL|READONLY
State="TEST"
[FIELD 3]
Type=CheckBox
NOtify=
TEXT= Ignore
FLAGS=NOtify
State=0
Left=0
Right=-1 
Top=110 
Bottom=120 
The Next-Button is correctly disabled. But when I do a click in the checkbox, the button is not enabled.

Where is the errror?

Any ideas?

Thank you very much...
Red Wine#
You need to capture the checkbox with notify flag and re-enable the button when checkbox is checked.

See following example for details,