gclass
15th November 2011 08:57 UTC
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
MSG
15th November 2011 09:55 UTC
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
gclass
15th November 2011 10:58 UTC
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
MSG
15th November 2011 11:11 UTC
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.
gclass
15th November 2011 11:50 UTC
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
MSG
15th November 2011 14:28 UTC
Yeah, a pop is all you need. Looks good.
gclass
15th November 2011 14:31 UTC
thx a lot