Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Visual C++ popup menus...

Status
Not open for further replies.

danielnogo

Programmer
Jan 20, 2005
16
0
0
US
Popup menus have been the bane of my existance in visual c++. Im following a tutorial that came with a cd I got and this is the code it gives me for OnContextMenu():

void CPopupMenuDlg::OnContextMenu(CWnd* pWnd, CPoint point)
{
// TODO: Add your message handler code here
CMenu *m_lMenu; // A pointer to the menu
CPoint m_pPoint; // A copy of the mouse position


m_pPoint = point;
// Convert the position to a screen position
ClientToScreen(&m_pPoint);

m_lMenu - GetMenu();

m_lMenu = m_lMenu->GetSubMenu(0);

m_lMenu->TrackPopupMenu(TPM_CENTERALIGN + TPM_LEFTBUTTON,
m_pPoint.x, m_pPoint.y, this, NULL);




}

It doesnt work, I even pasted the code from the tutorial in my code, just to make sure I have it right. Heres the warnings I get:
warning C4552: '>>' : operator has no effect; expected operator with side-effect
local variable 'm_lMenu' used without having been initialized

Can anyone help?
 
Well, the message says it all
"local variable 'm_lMenu' used without having been initialized"

And what is this?
Code:
m_lMenu - GetMenu();

Assuming you have all context menus in the same menu resource, showing them is a simple as:
Code:
void Whatever::OnContextMenu(CWnd*, CPoint pt) 
{

	CMenu allContextMenus;
	allContextMenus.LoadMenu(IDR_ALL_CONTEXTMENUS);
	CMenu* contextMenu = m.GetSubMenu(0);  // Get first menu, index 0

	contextMenu->TrackPopupMenu(TPM_LEFTALIGN |TPM_RIGHTBUTTON, pt.x, pt.y, this);
}

/Per
[sub]
www.perfnurt.se[/sub]
 
Copy/paste error by me.
Code:
m.GetSubMenu(0)
shouldf of course be
Code:
allContextMenus.GetSubMenu(0)

/Per
[sub]
www.perfnurt.se[/sub]
 
Hey, thanks alot, it worked :)
But is there a way to display the whole menu as a popup, not just the sub menus?
 
>But is there a way to display the whole menu as a popup, not just the sub menus?

A popu-up menu is usually just one menu (ie a sub-menu), you never get a whole row of menus when you right-click. The pop-pup can contain sub menus itself of course and you can cram as much as you like into the pop-up menu.

/Per
[sub]
www.perfnurt.se[/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top