cpx
cpx

Reputation: 17577

Right click on Button

I see there 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?

Upvotes: 5

Views: 5229

Answers (6)

omatai
omatai

Reputation: 3728

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.

Upvotes: 0

Michael Dunn
Michael Dunn

Reputation: 429

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.

Upvotes: 2

baash05
baash05

Reputation: 4516

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".

Upvotes: 0

Murray
Murray

Reputation: 690

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

Upvotes: 2

Reallyethical
Reallyethical

Reputation: 1825

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

Upvotes: 0

Brian R. Bondy
Brian R. Bondy

Reputation: 347556

You can use WM_RBUTTONDOWN, WM_RBUTTONUP, and WM_RBUTTONDBLCLK.

Upvotes: 2

Related Questions