Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ActiveX VC++
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 1-May-13 1:26am
pani681.1K
Comments
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;

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

Rate this: bad
good
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.
 

See:[^]
  Permalink  
Comments
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?
 
Pani
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 OriginalGriff 587
1 Sergey Alexandrovich Kryukov 479
2 Maciej Los 305
3 Mathew Soji 195
4 Afzaal Ahmad Zeeshan 170
0 OriginalGriff 7,356
1 Sergey Alexandrovich Kryukov 6,777
2 DamithSL 5,461
3 Manas Bhardwaj 4,916
4 Maciej Los 4,475


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