Archive: dependent checkbox in dialog


dependent checkbox in dialog
Hello,
I used the dialog designer to generate a dialog.
I have 3 checkboxes and would like to enable #2 and #3 only if #1 is checked.

these are the functions:


Function fnc__1_Create

; === _1 (type: Dialog) ===
nsDialogs::Create 1018
Pop $hCtl__1
${If} $hCtl__1 == error
Abort
${EndIf}

; === CheckBox3 (type: Checkbox) ===
${NSD_CreateCheckbox} 68 192 291 18 "this is checkbox 3"
Pop $hCtl__1_CheckBox3
${If} $hCtl__1_CheckBox3_state == ${BST_CHECKED}
${NSD_Check} $hCtl__1_CheckBox3
${EndIf}

; === CheckBox2 (type: Checkbox) ===
${NSD_CreateCheckbox} 68 174 243 18 "this is checkbox 2"
Pop $hCtl__1_CheckBox2
${If} $hCtl__1_CheckBox2_state == ${BST_CHECKED}
${NSD_Check} $hCtl__1_CheckBox2
${EndIf}

; === CheckBox1 (type: Checkbox) ===
${NSD_CreateCheckbox} 46 155 233 23 "this is checkbox 1"
Pop $hCtl__1_CheckBox1
${If} $hCtl__1_CheckBox1_state == ${BST_CHECKED}
${NSD_Check} $hCtl__1_CheckBox1
${EndIf}
${NSD_Check} $hCtl__1_CheckBox1

FunctionEnd


; dialog show function
Function fnc__1_Show
Call fnc__1_Create
nsDialogs::Show $hCtl__1
FunctionEnd

; function to remember the selections made in case of back to previous page
Function nsDialogsPageLeave
${NSD_GetState} $hCtl__1_CheckBox1 $hCtl__1_CheckBox1_state
${NSD_GetState} $hCtl__1_CheckBox2 $hCtl__1_CheckBox2_state
${NSD_GetState} $hCtl__1_CheckBox3 $hCtl__1_CheckBox3_state
FunctionEnd


and I call them like:

Page custom fnc__1_Show nsDialogsPageLeave


will be glad to have some help,

Thx
G

Use the OnClick macro on checkbox 1 to uncheck and disable checkboxes 2&3 if the new checkbox state is unchecked.
http://nsis.sourceforge.net/Docs/nsD...ml#ref-onclick


MSG, thx for that.

I added onclick macro to call a function to disable or enable the 2+3 checkboxes and it is working great:

${NSD_CreateCheckbox} 46 155 233 23 "checkbox1"
Pop $hCtl__1_CheckBox1
${NSD_OnClick} $hCtl__1_CheckBox1 DisableCheckbox
${If} $hCtl__1_CheckBox1_state == ${BST_CHECKED}
${NSD_Check} $hCtl__1_CheckBox1
${EndIf}
${NSD_Check} $hCtl__1_CheckBox1
in the function I cant get it work right:
Function DisableCheckbox
${If} $hCtl__1_CheckBox1_state == ${BST_UNCHECKED}
EnableWindow $hCtl__1_CheckBox2 0
EnableWindow $hCtl__1_CheckBox3 0
${Else}
EnableWindow $hCtl__1_CheckBox2 1
EnableWindow $hCtl__1_CheckBox3 1
${EndIf}
FunctionEnd
when I remove the IF it is working and disable the checkboxes..

thx

First of all: As you can read in the manual, first you need to to pop the control's HWND off the stack. Even if you already know it, you cannot leave it there and cause stack corruption.

Second, you need to get the new state of the checkbox before you can do If State == unchecked. Use NSD_GetState.


thx, working fine now.
can you take a look that I handle the stack correctly, I dont get error so I want to be sure :)


Function DisableCheckbox
;MessageBox MB_OK "$hCtl__1_CheckBox1_state and $hCtl__1_CheckBox1"
Pop $hCtl__1_CheckBox1
${NSD_GetState} $hCtl__1_CheckBox1 $hCtl__1_CheckBox1_state
${If} $hCtl__1_CheckBox1_state == ${BST_UNCHECKED}
EnableWindow $hCtl__1_CheckBox2 0
EnableWindow $hCtl__1_CheckBox3 0
${Else}
EnableWindow $hCtl__1_CheckBox2 1
EnableWindow $hCtl__1_CheckBox3 1
${EndIf}
FunctionEnd


thx
G

Yeah, a pop is all you need. Looks good.


thx a lot