Old 3rd August 2021, 20:36   #1
stopthemess
Junior Member
 
Join Date: Dec 2012
Posts: 11
NSD_OnClick is triggered on focus

Is it a known behavior? How can I filter only click events?

My code looks similar to this:

code:

${NSD_CreateRadioButton} 1 2 3 4 $R1
Pop $R1
${NSD_OnClick} $R1 OnRadioClick



The callback runs when I click on the button and when I focus on it. I need only click events. Thanks.
stopthemess is offline   Reply With Quote
Old 3rd August 2021, 23:34   #2
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,411
Radio buttons are usually part of a group and you cannot focus a radio without selecting it. When you are notified you should just check which of the radios in the group is selected and take appropriate action.

In the most common case you don't even add a handler for a radio, you just check its state in the page leave callback function. Only catch the OnClick if you dynamically need to change something else on the page when the radio changes.

Internally in Windows check-boxes and radio buttons are implemented as buttons and nsDialogs just catches the BN_CLICKED event for OnClick.

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 4th August 2021, 07:01   #3
stopthemess
Junior Member
 
Join Date: Dec 2012
Posts: 11
> catches the BN_CLICKED event

Where can I see this code? I think the notification code is just not checked, and so BN_SETFOCUS triggers the callback as well.

You can reproduce by compiling this example and pressing tab several times, you'll see a message box while you shouldn't:
https://nsis.sourceforge.io/NsDialog...ton_selections
stopthemess is offline   Reply With Quote
Old 4th August 2021, 08:51   #4
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,411
Quote:
if (HIWORD(wParam) == BN_CLICKED && (ctl->type == NSCTL_BUTTON || ctl->type == NSCTL_LINK))
but why does it matter? Why is the focus event causing you trouble?

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 4th August 2021, 10:40   #5
stopthemess
Junior Member
 
Join Date: Dec 2012
Posts: 11
Because I switch between "Next >" and "Install" button text depending on the selected radio button. Now there's a bug in which I switch the text while the user didn't actually select the ratio button. I can work around it by checking whether the button is actually selected, but it's still a bug.

I found the code you referenced, but still the bug exists and I showed how to reproduce it easily. Looks like the code you provided is not involved in calling the callback in the scenario when focus is changed, but I didn't debug enough to understand why it's called.
stopthemess is offline   Reply With Quote
Old 4th August 2021, 12:35   #6
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,411
Radio buttons sends BN_CLICKED when it gets focus, don't ask me why.

Quote:
...generation of BN_CLICKED messages when the button receives focus.
You can do
PHP Code:
!define /IfNDef BM_SETDONTCLICK 0xF8 Vista and later only?
SendMessage $hMyRadio ${BM_SETDONTCLICK1 0 
but when you use radio buttons, it is important to use groups and "check" one as the default. After that you don't care why you got notified:

PHP Code:
!include nsDialogs.nsh
Page Custom pre
Function pre
nsDialogs
::Create 1018
Pop 
$0
${NSD_CreateFirstRadioButton0 0 406"Configure $(^Name)"
Pop $1
${NSD_OnClick} $1 RadioChanged
${NSD_CreateAdditionalRadioButton0 12406"Just install now"
Pop $2
${NSD_OnClick} $2 RadioChanged
SendMessage 
$${BM_CLICK"" "" Set a default
nsDialogs::Show
FunctionEnd

Function RadioChanged
Pop 
$3
GetDlgItem 
$0 $hWndParent 1
${NSD_GetChecked} $$3
${If} $<> ${BST_UNCHECKED}
    ${
NSD_SetText} $"$(^NextBtn)"
${Else}
    ${
NSD_SetText} $"$(^InstallBtn)"
${EndIf}
FunctionEnd 

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 4th August 2021, 14:07   #7
stopthemess
Junior Member
 
Join Date: Dec 2012
Posts: 11
What the heck Microsoft, and BN_CLICKED's documentation has no mention of focus!

Thank you, BM_SETDONTCLICK fixes it nicely.
stopthemess is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump