If the menu items you want disable/enable are the top-most menu items, then can use the EnableMenuItem member function of the CMenu class within CMainFrame
The function below disables/enables certain menu options according to global/member boolean variables.
void CMainFrame::SetMenuItems()
{
CMenu* pMenu = GetMenu();
if (m_bDisableDatabases)
{
pMenu->EnableMenuItem(TOPMENU_DATABASES, MF_BYPOSITION | MF_DISABLED | MF_GRAYED);
}
else
{
pMenu->EnableMenuItem(TOPMENU_DATABASES, MF_BYPOSITION | MF_ENABLED);
}
DrawMenuBar();
}
If the menus you want to disable/enable are sub-menus, then you can use Class Wizard against the menus resource, go to the Message Maps tab, select resource in the left-hand pane & the UPDATE_COMMAND_UI in the right-hand pane. Click on 'Add Function'. Inside the function you can do the following:-
void CMainFrame::OnUpdateMySubMenu(CCmdUI* pCmdUI)
{
pCmdUI->Enable(TRUE); // or FALSE to disable it !
}
Spencer Window (not a joke name)