Click here to Skip to main content
15,895,084 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I've created an ActiveX control. I would like to have a pop-up context menu for when the user right clicks the mouse. However, my search has been proved fruitless.

I've already created the menu in the resource editor. When I add the WM_CONTEXTMENU it generates the code below.

C++
void CMyActiveXCtrl::OnContextMenu(CWnd* /*pWnd*/, CPoint /*point*/)
{
	// TODO: Add your message handler code here
}


What I would like to know is how do I accomplish this and can anyone point me in the right direction.

BTW: I'm using Visual C 2008.
Posted
Comments
pani68 1-May-13 7:03am    
I did the same thing as explained in Solution 2 but my menu items are disabled. Any ideas why this happens and how to get these enabled?

Pani

you'll have to catch the WM_RBUTTONUP event and then use CreatePopupMenu and TrackPopupMenu

Best also to work out where the mouse is in relation to the desktop edges, so your menu doesn't display 'out of screen' [MapWindowPoints(yourHWND,NULL,...)]
 
Share this answer
 
Comments
Alton Williams 6-Jan-12 17:51pm    
Sorry for the delay. I've found the solution. I have to also have to handle WM_CONTEXTMENU. Thanks for telling me about the TrackPopupMenu
method.
I found the solution.
Since my contol is a shape using CRgn First I have to catch the WM_RBUTTONUP message this ensures that point is in the region. Then have to also handle WM_CONTEXTMENU event. Because if I don't the popup menu can appear in the wrong place on the screen.
With the genrated code
C++
void CMyActiveXCtrl::OnContextMenu(CWnd* /*pWnd*/, CPoint /*point*/)
{
    // TODO: Add your message handler code here
}

I comment out the paramaters giving
C++
void CMyActiveXCtrl::OnContextMenu(CWnd* pWnd, CPoint point)
{
    // TODO: Add your message handler code here
}


Inside the body I inserted the following
C++
myMenu.TrackPopupMenu(MY_ALIGNEMT_FLAGS,point.x, point.y,this);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900