p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Ivor Horton's Beginning Visual C++ 2005 (http://p2p.wrox.com/forumdisplay.php?f=249)
-   -   CH 15 Context Menu - Element Menu Items (http://p2p.wrox.com/showthread.php?t=70226)

Razzy The Pug August 24th, 2008 02:33 PM

CH 15 Context Menu - Element Menu Items
 
Hi All,

Having an issue with "Checking the Context Menu Items." I added the code for the list below and successfully compiled:

page 794: Implementing a Context Menu
page 795: Associating a Menu with a Class
page 797: Choosing a Context Menu
page 798: Identifying a Selected Element
page 800: Exercising the Pop-Ups

No problem so far. In "Checking the Context Menu Items" (page 800), the following code in void CSketcherView::OnContextMenu:

******** code **************
{
CMenu menu;
menu.LoadMenu(IDR_CURSOR_MENU); // Load the Context Menu

// Set Check Marks if it's the no Element Menu
if (m_pSelected == 0)
{
COLORREF Color = GetDocument()->GetElementColor();
menu.CheckMenuItem(ID_COLOR_BLACK,(BLACK == Color?MF_CHECKED:MF_UNCHECKED)|MF_BYCOMMAND);
menu.CheckMenuItem(ID_COLOR_RED,(RED == Color?MF_CHECKED:MF_UNCHECKED)|MF_BYCOMMAND);
menu.CheckMenuItem(ID_COLOR_GREEN,(GREEN == Color?MF_CHECKED:MF_UNCHECKED)|MF_BYCOMMAND);
menu.CheckMenuItem(ID_COLOR_BLUE,(BLUE == Color?MF_CHECKED:MF_UNCHECKED)|MF_BYCOMMAND);

// Check Element Menu Items
unsigned int ElementType = GetDocument()->GetElementType();
menu.CheckMenuItem(ID_ELEMENT_LINE,(LINE == Color?MF_CHECKED:MF_UNCHECKED)|MF_BYCOMMAND);
menu.CheckMenuItem(ID_ELEMENT_RECTANGLE,(RECTANGLE == Color?MF_CHECKED:MF_UNCHECKED)|MF_BYCOMMAND);
menu.CheckMenuItem(ID_ELEMENT_CIRCLE,(CIRCLE == Color?MF_CHECKED:MF_UNCHECKED)|MF_BYCOMMAND);
menu.CheckMenuItem(ID_ELEMENT_CURVE,(CURVE == Color?MF_CHECKED:MF_UNCHECKED)|MF_BYCOMMAND);
}

CMenu* pPopup = menu.GetSubMenu(m_pSelected == 0 ? 1 : 0); // Get the First Menu
ASSERT(pPopup != NULL); // Ensure it's There

// Display the Popup Menu
pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y, this);
}
******** end code **************

It all compiles fine, but when I right click on an element in the Sketcher program, only the menu color item is checked corectly. The menu element item is not checked at all.

An help would be greatly appreciated.

thanks,
Razzy







Dan6 October 11th, 2008 07:19 AM

Hi Razzy,

I see that you posted this a while ago now, so you've probably already figured out what's wrong. But just in case...

This looks suspiciously like a copy and paste error. In the lines of code which handle the element type section of the context menu the tests you're performing are against the 'Color' variable e.g. 'LINE == Color'. I think you need to change these tests to act on the 'ElementType' variable e.g. 'RECTANGLE == ElementType ...".

I think this should solve your problem. I hope that helps.

Dan


Razzy The Pug November 9th, 2008 03:53 PM

Dan,

Yes thanks. That was it.

Razzy



All times are GMT -4. The time now is 01:51 AM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.