Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: ActiveX VC++
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 1:26am
Style-7 at 1-May-13 8:16am
How do you create handle of menu?
pani68 at 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 at 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 at 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
0 Sergey Alexandrovich Kryukov 195
1 Peter Leow 160
2 Zoltán Zörgő 160
3 BillWoodruff 85
4 bling 70
0 Sergey Alexandrovich Kryukov 9,568
1 OriginalGriff 6,901
2 Peter Leow 4,737
3 Zoltán Zörgő 4,404
4 CHill60 2,932

Advertise | Privacy | Mobile
Web01 | 2.8.150129.1 | Last Updated 2 May 2013
Copyright © CodeProject, 1999-2015
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