Board index » Visual Studio » Add Context Menu to Button

Add Context Menu to Button

Visual Studio23
Hi,



I have two buttons in my dialog screen and I want to add a right click

context menu to the second button. The first button already has a context

menu and works fine. I have everything I need except how to associate the

menu with the second button. I don't see a context menu selection on the

basic properties or property event list for either button.



How do I get the second button to respond to the right click event and

display the menu that I want from the list of menus in the resource menu

folder?



Thanks!

--

Dave Boyd


-
 

Re:Add Context Menu to Button

Hi Dave,



Quote
How do I get the second button to respond to the right click

event and display the menu that I want from the list of menus

in the resource menu folder?



Since the common MFC controls don't provide this functionality on their

own; your first button must have already applied its own custom routine to

invoke its context menu.



If you could not use the first button's routine to your second button, I

suggest you refer to the following article's approach, which introduced a

detailed walkthrough on how to do this:



Using a Context Menu on a Control

www.functionx.com/visualc/howto/contextmenu.htm">www.functionx.com/visualc/howto/contextmenu.htm





Thanks for your understanding!



Best regards,



Gary Chang

Microsoft Community Support

--------------------

Get Secure! ¡§C www.microsoft.com/security

Register to Access MSDN Managed Newsgroups!

http://support.microsoft.com/default.aspx?scid" rel="nofollow" target="_blank">support.microsoft.com/default.aspx=/servicedesks/msdn/nospam.asp

&SD=msdn



This posting is provided "AS IS" with no warranties, and confers no rights.



-

Re:Add Context Menu to Button

Gary,



Thanks for the quick reply, I had already found the article you referenced.

Here's the problem: I'm using the new, improved VS 2003. Reading the

recommended article carefully, I find that the property box for my button has

no message button. Explicitly the property page for the selected button has:

Categorized, Alphabetic, Properties, Control Events and a greyed out icon

called Property Pages. What now?



Note: you are correct the OnContextMenu handler is done and working, but

even presented with the source code I can't figure out how it is "custom"

attached to the working button so that I could duplicate it for the new

button.



Thanks,

--

Dave Boyd



PS If you could show me in the updated for VS 2003 Microsoft MFC

documetation how any of this works I would be eternally grateful! (--maybe I

should install VS 2005 documenation just to get some decent help??)



""Gary Chang[MSFT]"" wrote:



Quote
Hi Dave,



>How do I get the second button to respond to the right click

>event and display the menu that I want from the list of menus

>in the resource menu folder?



Since the common MFC controls don't provide this functionality on their

own; your first button must have already applied its own custom routine to

invoke its context menu.



If you could not use the first button's routine to your second button, I

suggest you refer to the following article's approach, which introduced a

detailed walkthrough on how to do this:



Using a Context Menu on a Control

www.functionx.com/visualc/howto/contextmenu.htm">www.functionx.com/visualc/howto/contextmenu.htm





Thanks for your understanding!



Best regards,



Gary Chang

Microsoft Community Support

--------------------

Get Secure! ¡§C www.microsoft.com/security

Register to Access MSDN Managed Newsgroups!

http://support.microsoft.com/default.aspx?scid" rel="nofollow" target="_blank">support.microsoft.com/default.aspx=/servicedesks/msdn/nospam.asp

&SD=msdn



This posting is provided "AS IS" with no warranties, and confers no rights.





-

Re:Add Context Menu to Button

Hi Dave,,



Quote
Reading the recommended article carefully, I find that the

property box for my button has no message button.



"9. Display the dialog box and click its body

10.In the Properties window, click the Messages button"



It doesn't mean the property box of the target button, it means the

Property window of the parent dialog box, so in VS.NET 2003 IDE, just

select your project's dialog template in the Resource editor, the right

click it and select "Properties". Then in the its Property Sheet tool

window, Click the "Messages" button, you will get a list of the

message-handler function, and navigate to the "WM_ONCONTEXTMENU" item and

select "Edit Code" in its right listbox.



I suggest you refer to the Step 25 of that article, your application's

dialog class's OnContextMenu function should be like that...





Good Luck!



Best regards,



Gary Chang

Microsoft Community Support

--------------------

Get Secure! ¡§C www.microsoft.com/security

Register to Access MSDN Managed Newsgroups!

http://support.microsoft.com/default.aspx?scid" rel="nofollow" target="_blank">support.microsoft.com/default.aspx=/servicedesks/msdn/nospam.asp

&SD=msdn



This posting is provided "AS IS" with no warranties, and confers no rights.



-

Re:Add Context Menu to Button

Gary,



Okay, that clarifies where the message box is but that is not the problem.

The context handler is done and works fine. Something has to be done to the

non-working button itself.



When I right-click the working button the context menu appears. When I

right click the non-working button on the same dialog screen nothing happens.

Is every button on the screen supposed to respond to a right click once the

context event has a handler?? If it is, I've got a buggy button that doesn't

work (how do I fix it?). If you have to some how attach a menu to each

button, I need to know how to do that. Which step in the referenced

procedure does that?



Thanks,

--

Dave Boyd





""Gary Chang[MSFT]"" wrote:



Quote
Hi Dave,,



>Reading the recommended article carefully, I find that the

>property box for my button has no message button.



"9. Display the dialog box and click its body

10.In the Properties window, click the Messages button"



It doesn't mean the property box of the target button, it means the

Property window of the parent dialog box, so in VS.NET 2003 IDE, just

select your project's dialog template in the Resource editor, the right

click it and select "Properties". Then in the its Property Sheet tool

window, Click the "Messages" button, you will get a list of the

message-handler function, and navigate to the "WM_ONCONTEXTMENU" item and

select "Edit Code" in its right listbox.



I suggest you refer to the Step 25 of that article, your application's

dialog class's OnContextMenu function should be like that...





Good Luck!



Best regards,



Gary Chang

Microsoft Community Support

--------------------

Get Secure! ¡§C www.microsoft.com/security

Register to Access MSDN Managed Newsgroups!

http://support.microsoft.com/default.aspx?scid" rel="nofollow" target="_blank">support.microsoft.com/default.aspx=/servicedesks/msdn/nospam.asp

&SD=msdn



This posting is provided "AS IS" with no warranties, and confers no rights.





-

Re:Add Context Menu to Button

Gary,



Disregard my previous question. My code is filtering the OnContext event

incorrectly now that I finally understand how that "association" is made.

(i.e. Using the current mouse position and returning the control ID of the

current -- in this case non-working button with GetDlgCtrlID.) The

non-working button is erroneously treated as background and therefore skips

the pop-up menu activation. Thanks for your help.

--

Dave Boyd





"daveboyd" wrote:



Quote
Gary,



Okay, that clarifies where the message box is but that is not the problem.

The context handler is done and works fine. Something has to be done to the

non-working button itself.



When I right-click the working button the context menu appears. When I

right click the non-working button on the same dialog screen nothing happens.

Is every button on the screen supposed to respond to a right click once the

context event has a handler?? If it is, I've got a buggy button that doesn't

work (how do I fix it?). If you have to some how attach a menu to each

button, I need to know how to do that. Which step in the referenced

procedure does that?



Thanks,

--

Dave Boyd





""Gary Chang[MSFT]"" wrote:



>Hi Dave,,

>

>>Reading the recommended article carefully, I find that the

>>property box for my button has no message button.

>

>"9. Display the dialog box and click its body

>10.In the Properties window, click the Messages button"

>

>It doesn't mean the property box of the target button, it means the

>Property window of the parent dialog box, so in VS.NET 2003 IDE, just

>select your project's dialog template in the Resource editor, the right

>click it and select "Properties". Then in the its Property Sheet tool

>window, Click the "Messages" button, you will get a list of the

>message-handler function, and navigate to the "WM_ONCONTEXTMENU" item and

>select "Edit Code" in its right listbox.

>

>I suggest you refer to the Step 25 of that article, your application's

>dialog class's OnContextMenu function should be like that...

>

>

>Good Luck!

>

>Best regards,

>

>Gary Chang

>Microsoft Community Support

>--------------------

>Get Secure! ¡§C www.microsoft.com/security

>Register to Access MSDN Managed Newsgroups!

>http://support.microsoft.com/default.aspx?scid" rel="nofollow" target="_blank">support.microsoft.com/default.aspx=/servicedesks/msdn/nospam.asp

>&SD=msdn

>

>This posting is provided "AS IS" with no warranties, and confers no rights.

>

>

-

Re:Add Context Menu to Button

That's OK, Dave, I am glad to help you on this issue:)



Have a happy weekend!





Best regards,



Gary Chang

Microsoft Community Support

--------------------

Get Secure! ¡§C www.microsoft.com/security

Register to Access MSDN Managed Newsgroups!

http://support.microsoft.com/default.aspx?scid" rel="nofollow" target="_blank">support.microsoft.com/default.aspx=/servicedesks/msdn/nospam.asp

&SD=msdn



This posting is provided "AS IS" with no warranties, and confers no rights.



-