Greetings
My aim is to show a context menu in a dialog app and check/uncheck its only
menu item.
To achieve that , I did the following:
1. Created a dialog app using appwizard
2. Added a handler for the WM_RBUTTONUP message in my dialog class which
shows a context menu:
(something like the following)
void CMyDlg::OnRButtonUp(UINT nFlags, CPoint point)
{
// Create the context menu
CMenu MyContextMenu;
// Load the menu
MyContextMenu.LoadMenu(IDR_MY_MENU);
// Show the menu
ClientToScreen(&point);
MyContextMenu.GetSubMenu(0)->TrackPopupMenu(TPM_LEFTALIGN| TPM_RIGHTBUTTON
,point.x,point.y,this);
}
As I said earlier, my menu only has an item which I want to check or
uncheck.
So I added an UPDATE_COMMAND_UI handler for my menu item like this:
void CMyDlg::OnUpdate MyMenuMyItem(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck();
}
What's the problem?
Nothing happens!
When I step inside SetCheck() in debug mode, I see this function:
void CTestCmdUI::SetCheck(int)
{
// do nothing -- just want to know about calls to Enable
!!!!!!!!!!! )
}
This situation is quite frustrating.What am I doing wrong?
I would be gratefull to anyone who could provide me with an answer and
(hopefully) a solution.
Thanks in advance
George Sgouros
Hope this helps!
Bye!
- Gautam N. Lad / Vimal N. Lad
http://www.geocities.com/SiliconValley/Heights/1107
Dialogs have a different command-routing scheme. OnUpdateXxxx doesn't
get called.
Read MS Knowledge Base article:
Article ID: Q139469
This will give the skinny on command routing for dialogs, popups, and
popups in dialogs
Mike
----------------------------------------------------------------
CMenu menu;
VERIFY(menu.LoadMenu(CG_IDR_POPUP_HEX_EDIT));
CMenu* pPopup = menu.GetSubMenu(0);
ASSERT(pPopup != NULL);
pPopup->EnableMenuItem(ID_EDIT_UNDO, MF_GRAYED|MF_DISABLED|MF_BYCOMMAND);
pPopup->CheckMenuItem(ID_POPUP_AUTOMATICREFRESH, m_bAutomaticRefresh?
MF_CHECKED : MF_UNCHECKED );
if(!IsSelected())
{
pPopup->EnableMenuItem(ID_POPUP_SHOWGRAPH,
MF_GRAYED|MF_DISABLED|MF_BYCOMMAND);
pPopup->EnableMenuItem(ID_EDIT_CLEAR,
MF_GRAYED|MF_DISABLED|MF_BYCOMMAND);
pPopup->EnableMenuItem(ID_EDIT_CUT, MF_GRAYED|MF_DISABLED|MF_BYCOMMAND);
pPopup->EnableMenuItem(ID_EDIT_COPY,
MF_GRAYED|MF_DISABLED|MF_BYCOMMAND);
}
----------------------------------------------------------------