Quantcast
Channel: CodeGuru Forums - Visual C++ Programming
Viewing all articles
Browse latest Browse all 3044

How to Enable/Disable Menu Item 2 in OnUpdate Handler of Menu Item 1?

$
0
0
I have two menu items. When item 1 is disabled, I want item 2 to be disabled as well. In the OnUpdate handler of menu item 1, I have tried to use "t_pMenu = pCmdUI->m_pMenu;", "t_pMenu = pCmdUI->m_pSubMenu;" and "t_pMenu = pCmdUI->m_pParentMenu;" but I always get NULL t_pMenu. How can I achieve this purpose?

Code:

void CDummyView::OnUpdateMenuItem1(CCmdUI* pCmdUI)
{
        if(m_bShowMenuItem1) {
                pCmdUI->Enable(TRUE);
                CMenu * t_pMenu = pCmdUI->m_pSubMenu;
                if(t_pMenu != NULL)
                        t_pMenu->EnableMenuItem(ID_MENU_ITEM2, MF_ENABLED);
        }
        else {
                pCmdUI->Enable(FALSE);
                CMenu * t_pMenu = pCmdUI->m_pParentMenu;
                if(t_pMenu != NULL)
                        t_pMenu->EnableMenuItem(ID_MENU_ITEM2, MF_GRAYED);
        }
}

void CDummyView::OnUpdateMenuItem2(CCmdUI* pCmdUI)
{
        ...
}

Thanks,
Brian

Viewing all articles
Browse latest Browse all 3044

Trending Articles