How could I resolve this Problem Disabling a Menu item ?
-
I have the following two classes : 1) A CDialog derived CDlgClass 2) A CCmdTarget derived CAnotherClass I am unable to disable an item of the launched context-menu. Please follow the comments below to track the problem.
In DlgClass.cpp
ON_COMMAND(ID_MENUITEM1, OnMenuItemEdit1Clicked)
ON_UPDATE_COMMAND_UI(ID_MENUITEM1, OnUpdateMenuItemEdit1)//On Right-clicking the dialog, this function is called
VOID CDlgClass::OnContextMenu(CWnd* pWnd, CPoint point)
{
//Here, another class' ShowContextMenu is called to load the menu and show it
m_pAnotherClass->ShowContextMenu( this, point);
}void CDlgClass::OnMenuItemEdit1Clicked()
{
//Control reaches here when menu item 1 is clicked
}void CDlgClass::OnUpdateMenuItemEdit1(CCmdUI* pCmdUI)
{
//Control is expected to reach here before the menu launches but doesn't do so. Why?
//I am expecting menu Item 1 to be disabled before it shows up.pCmdUI->Enable(FALSE);
}
In AnotherClass.cpp
VOID CAnotherClass::ShowContextMenu(CWnd *pDlg, CPoint point)
{
CMenu cmCtxtMenu;cmCtxtMenu.LoadMenu(IDR\_MENU\_OPTIONS); CMenu \*pcmPopupMenu = cmCtxtMenu.GetSubMenu(0); ASSERT(pcmPopupMenu); pcmPopupMenu->TrackPopupMenu (TPM\_RIGHTBUTTON|TPM\_LEFTALIGN, point.x, point.y, pDlg );
}
What could be the problem with disabling the menu item although I could actually activate the menu item handler properly? The function CDlgClass::OnUpdateMenuItemEdit1(CCmdUI* pCmdUI) itself is not getting called before launch of the menu, when the menu is loaded in a different class. What could be the reason ? Thanks in Advance.
-
I have the following two classes : 1) A CDialog derived CDlgClass 2) A CCmdTarget derived CAnotherClass I am unable to disable an item of the launched context-menu. Please follow the comments below to track the problem.
In DlgClass.cpp
ON_COMMAND(ID_MENUITEM1, OnMenuItemEdit1Clicked)
ON_UPDATE_COMMAND_UI(ID_MENUITEM1, OnUpdateMenuItemEdit1)//On Right-clicking the dialog, this function is called
VOID CDlgClass::OnContextMenu(CWnd* pWnd, CPoint point)
{
//Here, another class' ShowContextMenu is called to load the menu and show it
m_pAnotherClass->ShowContextMenu( this, point);
}void CDlgClass::OnMenuItemEdit1Clicked()
{
//Control reaches here when menu item 1 is clicked
}void CDlgClass::OnUpdateMenuItemEdit1(CCmdUI* pCmdUI)
{
//Control is expected to reach here before the menu launches but doesn't do so. Why?
//I am expecting menu Item 1 to be disabled before it shows up.pCmdUI->Enable(FALSE);
}
In AnotherClass.cpp
VOID CAnotherClass::ShowContextMenu(CWnd *pDlg, CPoint point)
{
CMenu cmCtxtMenu;cmCtxtMenu.LoadMenu(IDR\_MENU\_OPTIONS); CMenu \*pcmPopupMenu = cmCtxtMenu.GetSubMenu(0); ASSERT(pcmPopupMenu); pcmPopupMenu->TrackPopupMenu (TPM\_RIGHTBUTTON|TPM\_LEFTALIGN, point.x, point.y, pDlg );
}
What could be the problem with disabling the menu item although I could actually activate the menu item handler properly? The function CDlgClass::OnUpdateMenuItemEdit1(CCmdUI* pCmdUI) itself is not getting called before launch of the menu, when the menu is loaded in a different class. What could be the reason ? Thanks in Advance.