Click to See Complete Forum and Search --> : Disable an item in the main menu


Sandrine
July 16th, 1999, 02:28 AM
Hi!

How do I disable an item in the main menu of my window?

Thanks in advance

Sandrine

Fabi Pantera
July 16th, 1999, 03:55 AM
Add A UpdateCommand handler for the menu ID you want do disable it. In it implementation you may set :
pCmdUI->Enable(FALSE)
Let me know if this helps you.
Best regards,
Faby

real name
July 16th, 1999, 04:01 AM
look at (CMenu::)EnableMenuItem (MF_BYPOSITION), (CWindow::)GetMenu (from mainframe/AfxGetMainWnd())
if i remember well before long time i found any asserts in CMenu when i wanted to have action directly from main menu (not submenus)
maybe this helps you
t!

John Killingbeck
July 16th, 1999, 10:36 PM
Assuming a program named Program created with AppWizard MFC: from file ProgramView.cpp - ID_MENUITEM is the id of the menu item that you want to enable/disable. The ClassWizard bar should be at the top of the source code window in the default configuration. In ClassWizard select ID_MENUITEM from the CProgramView Object ID's list, and UPDATE_COMMAND_UI from the Messages list. Create the function as ClassWizard requests. The function name will be CProgramView::OnUpdateMenuItem. See the example below for a menu item named ID_RETRIEVE_1.

void CMandelbrotView::OnUpdateRetrieve1(CCmdUI* pCmdUI)
{
// Programmer created code
if ( // Enable condition // )
pCmdUI->Enable( TRUE );
else
pCmdUI->Enable( FALSE );
// End programmer generated code
}



The ClassWizard automatically generates the right pointer, and the call to Enable controls access and grays out the item in a single call. ClassWizard keeps programming errors down and your code consistent. Once you do this a couple of times it gets very fast. This works for all access points to the ID_MENUITEM function, menus, toolbars, etc.