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:
Hello,

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

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

Pani
Posted
Comments
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;

if(m_menu)
m_menu->CreatePopupMenu();


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_SEPARATOR,0,L"");
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.


See:[^]
   
Comments
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?

Pani
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