Disable some context menu items if no items are checked

Viewed 306

I have a tree view (CTreeView) that will show me a pop-up menu after I right-click my mouse on it. In my context menu there are only 3 items (i.e A, B, C) for selection and my tree view displays a long list of ordered foods designed with check-boxes. I would like to disable menu items A and B if no ordered foods are checked and enable them when any is.

I create CFoodView::OnUpdateItemA(CCmdUI* pCmdUI) //CFoodView inherits CTreeView and CFoodView::OnUpdateItemB(CCmdUI* pCmdUI) to handle their states like so

CFoodView::OnUpdateItemB(CCmdUI* pCmdUI)
{
    if TreeView has no items
    {
        pCmdUI->Enable(FALSE);
    }
    else
    {
        *Search* the tree to get selected items
        if None is checked
        {
            pCmdUI->Enable(FALSE);
        }
        else there are checked items
            pCmdUI->Enable(TRUE);
    }
}

Method CFoodView::OnUpdateItemA(CCmdUI* pCmdUI) is the same.

I think this isn't a correct way to handle this GUI feature.

1 Answers
Related