Search code examples
nsis

Two checkboxes on a NSIS license page


I am trying to do pretty much what is being asked here but due to the complexity of the syntax and shortage of time, I need someone to help me out on this.

I have spent a couple of hours try to get TWO checkboxes shown instead of one but I keep failing. The NSIS syntax is killing me and I can't seem to get the params to the second USER32::CreateWindowEx right. I want to display the second checkbox below (or to the right) of the first one.

So far I have done the following modifications but this doesn't seem to create the second checkbox (please see the original post for the rest of the code).

; ---<snip>---
System::Call 'USER32::CreateWindowEx(i0,t "Button",t "Some option",i ${__NSD_CheckBox_STYLE},ir6,ir7,ir8,ir9,ir0,i666,i0,i0)i.r2'
System::Call 'USER32::CreateWindowEx(i0,t "Button",t "Second option",i ${__NSD_CheckBox_STYLE},ir6+100,ir7,ir8,ir9,ir0,i667,i0,i0)i.r3'
SendMessage $0 ${WM_GETFONT} 0 0 $0
SendMessage $2 ${WM_SETFONT} $0 1
SendMessage $3 ${WM_SETFONT} $0 1
${NSD_SetState} $2 1 ;check it
${NSD_SetState} $3 1 ;check it
FunctionEnd

Function licleave
FindWindow $5 "#32770" "" $HWNDPARENT
GetDlgItem $0 $5 666
GetDlgItem $1 $5 667
${NSD_GetState} $0 $0
${NSD_GetState} $1 $1
MessageBox mb_ok "Checkbox=$0 $1"
FunctionEnd

Solution

  • You cannot do math like ir6+100 in a system::call (You can only OR simple numbers), try IntOp $6 $6 + 100 before you create the second checkbox.

    Edit:

    The code from the other answer also gave the checkbox the same width as the dialog so any other control added to the right of it will appear behind it.

    You must adjust the size of the first checkbox as well:

    ...
    IntOp $8 $8 / 2 ; Use half the width
    System::Call 'USER32::CreateWindowEx(i0,t "Button",t "Some option",i ${__NSD_CheckBox_STYLE},ir6,ir7,ir8,ir9,ir0,i666,i0,i0)i.r2'
    IntOp $6 $6 + $8 ; Offset 2nd checkbox by the width of the first
    System::Call 'USER32::CreateWindowEx(i0,t "Button",t "Other option",i ${__NSD_CheckBox_STYLE},ir6,ir7,ir8,ir9,ir0,i667,i0,i0)i.r3'
    ...