Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


spurious BN_CLICKED messages

Posted on 1998-06-10
Medium Priority
Last Modified: 2013-12-03
My application has a window which has several controls in it.  When I click on one of the buttons, I get two WM_COMMAND messages of type BN_CLICKED in response, one for press and one for release.  I return from the WindowProc call with a 0 to signify that the message was handled.  If I click on any of the other controls, I get the same message for the first control before I get one for the second control.  Are there any reasons this type of message could be triggered by anything other than a click on the right button?
Question by:pschwamb
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Expert Comment

ID: 1407492
Are you possibly setting capture to the button and forgetting to release it on the first button up message?

Expert Comment

ID: 1407493
BN_CLICKED is undistinguishable from WM_COMMAND created by, say, menu item. Are you posting/sending WM_COMMMAD messages to yourself?


Author Comment

ID: 1407494
Ok, I figured out that it's a problem with focus events. When I click on the button, a message gets sent to another program which pops up an error window (which takes focus away from the button) and sends a message back to the first program telling it to clear the button.  As soon as the first program's window is clicked on (anywhere) again, the button gets another focus event and another BN_CLICKED message, which triggers the error message again (yuck!).  My question should really be: what is a good way around this?
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.


Accepted Solution

tma050898 earned 100 total points
ID: 1407495
Is the message sent or posted? If it's sent, you can set a local static flag before the SendMessage. Then while your function is blocked on the SendMessage call, your function is reentered and the static flag can be checked. If the flag is on, you don't do anything. After the SendMessage returns, turn the flag back off.



Author Comment

ID: 1407496
The solution I came up with was to ignore every BN_CLICKED message after a focus event.

Expert Comment

ID: 1407497

I have no problem being graded poorly if I give out a poor effort and/or answer. However, why did you grade me with a 'D' when I took my time to help you? If I didn't answer your question, the proper way to have handled it would have been to reject my answer; NOT insult and embarass me with a 'D'!!!



Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
This article describes how to programmatically preset the "Pages per Sheet" option that's available with most printer drivers.   This setting lets you do "n-Up" printing, where two, four, or more pages are printed on each sheet of paper. If your …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question