Click here to Skip to main content
13,044,467 members (59,627 online)
Rate this:
Please Sign up or sign in to 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 ...

Posted 1-May-13 0:26am
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

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 2 May 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100