Archive: Disable checkbox based on variable


Disable checkbox based on variable
Hi,

I have a custom page and i want that when i display it, a checkbox on that page should be enabled/disabled based on a variable which is set on a previous screen.

AdvOptionsStart is my Pre function (custom page)


Function AdvOptionsStart

${if} $AdvPage == 1 ; if adv button selected

${if} $INSTDIRExists == 0 ; disable checkbox in this case
FindWindow $0 "#32770" "" $HWNDPARENT
GetDlgItem $1 $HWNDPARENT 1201
EnableWindow $1 0
${endif}

!insertmacro MUI_HEADER_TEXT "Advanced Settings" "Specify advanced settings below."
!insertmacro MUI_INSTALLOPTIONS_DISPLAY "advanced.ini"
${endif}

FunctionEnd


INI File

; Ini file generated by the HM NIS Edit IO designer.
[Settings]
NumFields=2

[Field 1]
Type=Checkbox
Text=Copy installer to Storage
Left=16
Right=187
Top=22
Bottom=32
State=1

[Field 2]
Type=Checkbox
Text=Install for training
Left=16
Right=287
Top=41
Bottom=64
Flags=NOTIFY
State=0



This code is not working, as the checkbox is always enabled.

any ideas? Thanks ppl.

You should use the show function, not the prefunction.


This is how i am calling my custom page:

Page custom AdvOptionsStart AdvOptionsEnd

How do i use the show function here?


Err oops, it's a custom page. In that case your pre function IS your show function, my bad.

You cannot disable a checkbox before it is created. You probably need to write a flag to the checkbox entry in the ini file. It's been a very long time since I've used IntallOptions, so I'm not sure how/what exactly.


But i am successfully changing the State of radio buttons before they are displayed, i thought that disabling would be somewhat similar.


Function OptionsStart
!insertmacro MUI_HEADER_TEXT "$(INSTALL_OPTION_TITLE)" "$(INSTALL_OPTION_SUBTITLE)"

${If} $INSTDIRExists == 1
!insertmacro MUI_INSTALLOPTIONS_WRITE "options.ini" "Field 3" "State" $INSTDIR
!insertmacro MUI_INSTALLOPTIONS_WRITE "options.ini" "Field 1" "State" 1
!insertmacro MUI_INSTALLOPTIONS_WRITE "options.ini" "Field 2" "State" 0
!insertmacro MUI_INSTALLOPTIONS_WRITE "options.ini" "Field 3" "Flags" ""
!insertmacro MUI_INSTALLOPTIONS_WRITE "options.ini" "Field 4" "Flags" DISABLED
${Else}
!insertmacro MUI_INSTALLOPTIONS_WRITE "options.ini" "Field 4" "State" $INSTDIR
!insertmacro MUI_INSTALLOPTIONS_WRITE "options.ini" "Field 1" "State" 0
!insertmacro MUI_INSTALLOPTIONS_WRITE "options.ini" "Field 2" "State" 1
!insertmacro MUI_INSTALLOPTIONS_WRITE "options.ini" "Field 3" "Flags" DISABLED
!insertmacro MUI_INSTALLOPTIONS_WRITE "options.ini" "Field 4" "Flags" ""
${Endif}

!insertmacro MUI_INSTALLOPTIONS_DISPLAY "options.ini"

FunctionEnd


So is there a difference between changing State and disabling of controls?

State sets whether or not the checkbox is checked, so obviously that's not the same as disabling the checkbox.

The MUI_INSTALLOPTIONS_WRITE macro is indeed what you need for editing controls before they're displayed.


OK. then anybody knows how to disable a checkbox in a custom page?


You should use

!insertmacro MUI_INSTALLOPTIONS_INITDIALOG "advanced.ini"
; edit advanced.ini here
!insertmacro MUI_INSTALLOPTIONS_SHOW

instead of using MUI_INSTALLOPTIONS_DISPLAY.
MUI_INSTALLOPTIONS_DISPLAY will extract and thus overwrite your modified advanced.ini.

Anyway, why are you using InstallOptions?
Have a look at nsDialogs, it is way more flexible.

Edit: nvm