Click here to Skip to main content
14,733,889 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:

I created a simple AxctiveX control which would change its color in response to popup menu. I dynamically created a menu in the function
of the control. The problem is, if i call
, passing 'this' as a
, the popup commands are not enabled. Can someone please explain where I am going wrong? Is there something in the implementation of
that overrides the behavior of

that allows a Popup to function? If so - can i change it?

I am using VC 2008

Thanks in advance to anyone who can help ...

Style-7 1-May-13 8:16am
How do you create handle of menu?
pani68 1-May-13 12:47pm
I have a CMenu * member variable in the class.

Then I initialise it in the constructor like this:

m_menu = new CMenu;


In the OnContextMenu function I add the menu item and call OnPopupMenu as follows:

while(m_menu->DeleteMenu(0,MF_BYPOSITION) != FALSE); //

m_menu->AppendMenu(MF_STRING | MF_ENABLED,MENU_SAVE_TO_FILE,L"Save Graph to File");
m_menu->AppendMenu(MF_STRING | MF_ENABLED,MENU_CHANGE_COLOR,L"Change the color");

m_menu->TrackPopupMenu(TPM_LEFTALIGN|TPM_RIGHTBUTTON,point.x, point.y, this, NULL );

1 solution

TrackPopupMenu(TPM_LEFTALIGN|TPM_RIGHTBUTTON,point.x, point.y,  this, NULL );

I think you must pass a window handle, not "this".
See also.

pani68 2-May-13 11:31am
Thank you for the suggestion. But the problem is not solved. I get the same result even if I use the pointer returned by AfxGetMainWnd().

I am not sure which handle to pass in place of 'this'. Since the control is inherited from COleControl, I thought 'this' could be used in the function.

Any further ideas to solve the problem?

Style-7 3-May-13 7:24am
Try use GetDesktopWindow()

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