I have 30 checkboxes on my custom page ($Checkbox1, $Checkbox2, $Checkbox3, etc.) and a $CheckALL checkbox for checking and unchecking all checkboxes.
The "classic" checkbox code works, but it's very cumbersome...
Please tell me what code I should use to check and uncheck all checkboxes in a loop ?
I can't seem to use a variable for the checkbox numbers...
How to select all checkboxes on a custom page ?
6 posts
Assuming $Checkbox1 is the HWND, you can call FindWindow (you need the sibling parameter) in a loop until you get to the last checkbox.
If you treat a checkbox as a window, you can only use its class and text. Text is excluded right away, and marking checkboxes as classes in a loop is also a bad idea, since there are other checkboxes on the page besides the ones you need to mark... Or am I misunderstanding something...
Simple
!include nsDialogs.nsh
Page custom nsDialogsPage
Page InstFiles
Var First
Var Last
Function nsDialogsPage
nsDialogs::Create 1018
Pop $0
${NSD_CreateCheckBox} 0 0u 100% 12u "One"
Pop $First
${NSD_CreateCheckBox} 0 14u 100% 12u "Two"
Pop $0
${NSD_CreateCheckBox} 0 28u 100% 12u "Three"
Pop $Last
${NSD_CreateButton} 0 42u 52 12u "All"
Pop $0
${NSD_OnClick} $0 All
nsDialogs::Show
FunctionEnd
Function All
FindWindow $1 "#32770" "" $hWndParent ; Inner
StrCpy $0 $First
loop:
${NSD_Check} $0
IntPtrCmp $Last $0 end
FindWindow $0 "" "" $1 $0
Goto loop
end:
FunctionEnd Only some of them!include nsDialogs.nsh
Page custom nsDialogsPage
Page InstFiles
Function nsDialogsPage
nsDialogs::Create 1018
Pop $0
${NSD_CreateCheckBox} 0 0u 100% 12u "One"
Pop $0
nsDialogs::SetUserData $0 1 ; Mark it
${NSD_CreateCheckBox} 0 14u 100% 12u "Not me"
Pop $0
; Dont mark
${NSD_CreateCheckBox} 0 28u 100% 12u "Three"
Pop $0
nsDialogs::SetUserData $0 1 ; Mark it
${NSD_CreateButton} 0 42u 52 12u "Marked"
Pop $0
${NSD_OnClick} $0 Marked
nsDialogs::Show
FunctionEnd
Function Marked
FindWindow $1 "#32770" "" $hWndParent ; Inner
StrCpy $0 ""
loop:
nsDialogs::GetUserData $0
Pop $2
${If} $2 = 1
${NSD_Check} $0
${EndIf}
FindWindow $0 "Button" "" $1 $0
${IfThen} $0 P<> "" ${|} Goto loop ${|}
FunctionEnd Works great! Thanks!
ps What does P<> mean ? Namely - "P" - this is the parameter ? Unfamiliar syntax for NSIS...
ps What does P<> mean ? Namely - "P" - this is the parameter ? Unfamiliar syntax for NSIS...
The P (ptrdiff_t in C) and Z (size_t) prefixes just means the numbers are interpreted as pointer sized numbers (32 or 64-bit). In 32-bit NSIS, it does nothing (normal IntCmp) and in 64-bit, it turns into L<> etc.Originally Posted by stass View Postps What does P<> mean ? Namely - "P" - this is the parameter ? Unfamiliar syntax for NSIS...