Right click on Button
I see ther开发者_JAVA技巧e are BN_CLICKED and BN_DBLCLK notification messages for a button control. but how would i catch a right click message for any button control?
You can use WM_RBUTTONDOWN, WM_RBUTTONUP, and WM_RBUTTONDBLCLK.
BN_CLICKED is a notification message sent to the parent window of the button by the button itself. To intercept the WM_RBUTTONDOWN, etc messages you need to subclass the button since those are messages sent from Windows itself to the button window. See the section named "Instance Subclassing" in Safe Subclassing in Win32
Handle WM_CONTEXTMENU
. The advantage of this over handling right-button mouse messages is that your users will be able to use the keyboard equivalents to right-clicking.
NM_RCLICK is sent so look closer at the windows messages.
you can check on reciving BN_CLICKED to see if NM_RCLICK or even WM_RBUTTONDOWN
Not really an answer, but I think you might be able to catch the context menu on the button. (don't know the event off the top of my head). If you can catch the context menu press on the button, then it's the same as the right click.
the BUTTON down is not a good path. The click is only caught when the user does a button up. Try pressing a button and before you take your finger off the button, move your mouse off of it.. the up stroke isn't recorded for that button, nor is the click.
Again I know this isn't an answer, but it might be a clue. I'm a handheld guy, so most often I don't have a "right mouse button".
This is an old question, but still not satisfactorily answered as far as I'm concerned. I faced the same problem, found that the accepted answer simply didn't work - the messages mentioned are intercepted before I could get my hands on them; I simply could not use WM_RBUTTONDOWN and so on.
So people coming to this question really should know about this solution, which involves subclassing the button, handling the right mouse button message(s) in the subclass, using them to send an NM_RCLICK message back to the parent window.
精彩评论