Archive: Troubles when retrieving the state of a checkbox


Troubles when retrieving the state of a checkbox
Hi all

Using nsDialogs, I'm trying to check the state of a checkbox each time it's clicked.

First of all it seems like the nsDialogs::OnChange event isn't working for checkboxes... or am I wrong?

Instead I tryed the nsDialogs::OnClick event like this:

GetFunctionAddress $0 onClick
nsDialogs::OnChange /NOUNLOAD $CHECKBOX $0

Function onClick
SendMessage $CHECKBOX ${BM_GETSTATE} 0 0 $0

${If} $0 == "1"
MessageBox MB_ICONEXCLAMATION|MB_OK "CheckBox checked"
${Else}
MessageBox MB_ICONEXCLAMATION|MB_OK "CheckBox unchecked"
${EndIf}

FunctionEnd

The problem is that the value/state of the checkbox is either 520 or 521, when checked in the onClick event handler.

But when checked in the leave page function it's 0 or 1.

How come this behavior? Is a bug or am I doing something wrong?

Best regards
Mikkel Munck Rasmussen


You should indeed use OnClick for checkboxes. You can use the ${NSD_OnClick} macro for easier usage.

520 and 521 are invalid states. I don't understand how you can get them from BM_GETSTATE.

Also, you forgot to pop the HWND in OnCLick. $CHECKBOX is passed on the stack and must be popped or else the stack would get corrupted.


Thanks a lot for your answer

Well, I based my code on the example that comes with the NSIS installation: NSISDIR\Examples\nsDialogs\example.nsi

And the problem is the same here. You can check this by changing the OnCheckbox function on line 69 to:

Function OnCheckbox

SendMessage $CHECKBOX ${BM_GETSTATE} 0 0 $0
MessageBox MB_OK "Checkbox state: $0"

FunctionEnd

And the problem is the same.


And what do you mean by "pop the HWND in OnClick"? Could you please provide an example?

Thanks in advance

\Mikkel


Use BM_GETCHECK instead. I don't know what are those 0x208 flags BM_GETSTATE adds, but BM_GETCHECK seems to work better.

As for popping, the examples were flawed. I fixed them for the next version. You just have to Pop one item from the stack every time your OnClick and OnChange callback function is called. That item is the HWND of the item for which the notification is sent.


Thanks a lot for your help!

BM_GETCHECK did the job.

\Mikkel