Archive: Custom page with checkbox and disabled "Next" button


Custom page with checkbox and disabled "Next" button
I am trying to create a custom page with behaviour like the license page with checkbox. I managed to create the page with the next button disable, but when I tick the checkbox the installer goes to the next page

How do I change the behaviour so when entering the page the "Next" button is disabled until the checkbox is ticked?

/Soren


You didn't say whether or not you were using MUI, so I'll just assume that you are...

Here's what I use on one of my installers. $hwnd and $hwnd_btn are 2 variables I use for holding dialog handles.

In my custom page display function, I use this:

!insertmacro MUI_INSTALLOPTIONS_INITDIALOG 'CustomPage.ini'
pop $hwnd ; handle to the window. (you may not need this, but I'd still POP anyway just to take it off the stack)
GetDlgItem $hwnd_btn $HWNDPARENT 1 ; This returns a handle to the NEXT button.
EnableWindow $hwnd_btn 0 ; this should disable the next button.
!insertmacro MUI_INSTALLOPTIONS_SHOW

Then, in your page leave function, check the state of the checkbox and display the next button if checked by using the command EnableWindows $hwnd_btn 1.

Note: You'd have to remember to use the NOTIFY flag on the checkbox. Otherwise, your script would never run the page's leave function.

Edit:
You should also remember to hide the NEXT button in your page leave function if the user decided to un-check the box after it's been checked.

Thanx for the help. I am using MUI. I am fairly new to NSIS installer, so if you could provide some more example code I would be greatfull.

When I put your code into my function it says:

Usage: GetDlgItem $(user_var: handle output) dialog item_id


I got it working partly. When I put a tick in the checkbox it jumps to the next page instead of just enabling the Next button. If you take a look at the License page with checkbox, you can toggle the Next button by checking and unchecking the checkbox. Any ideas?

Function Upgrade
!insertmacro MUI_INSTALLOPTIONS_INITDIALOG 'Upgrade.ini'
pop $hwnd
GetDlgItem $hwnd_btn $HWNDPARENT 1
EnableWindow $hwnd_btn 0
!insertmacro MUI_INSTALLOPTIONS_SHOW
FunctionEnd

Function UpgradeLeave
!insertmacro MUI_INSTALLOPTIONS_READ $R1 "Upgrade.ini" "Field 2" "State"
StrCmp $R1 "1" Enable Disable
Enable:
EnableWindow $hwnd_btn 1
Goto Exit
Disable:
Abort
Exit:
FunctionEnd


In your UpgradeLeave function, you need read the state from the 'settings' section to find out if the check box was checked or the next button was pressed. In addtion, you don't want to exit if someone clicks the check, but when they click "next".

Based on your example, I'll assume that the check box is field #2. Your function would therefore be something like this:


Function UpgradeLeave
!insertmacro MUI_INSTALLOPTIONS_READ $R0 "Upgrade.ini" "settings" "State"
StrCmp $R0 0 Exit ; exit if the next button was pressed. Otherwise, proceed:
!insertmacro MUI_INSTALLOPTIONS_READ $R1 "Upgrade.ini" "Field 2" "State"
StrCmp $R1 1 Enable Disable
Enable:
; Box is checked, so enable the next button:
EnableWindow $hwnd_btn 1
abort
Disable:
; Box is UN-checked, so disable the next button:
EnableWindow $hwnd_btn 0
Abort
Exit:
; user pressed 'next' so exit!
FunctionEnd

Notice how the EXIT label is never reached unless the user actually clicks 'next'.