Share via


CMenu::GetMenuState

UINTGetMenuState(UINTnID**,UINTnFlags)const;**

Return Value

The value 0xFFFFFFFF if the specified item does not exist. If nId identifies a pop-up menu, the high-order byte contains the number of items in the pop-up menu and the low-order byte contains the menu flags associated with the pop-up menu. Otherwise the return value is a mask (Boolean OR) of the values from the following list (this mask describes the status of the menu item that nId identifies):

  • MF_CHECKED   Acts as a toggle with MF_UNCHECKED to place the default check mark next to the item. When the application supplies check-mark bitmaps (see the SetMenuItemBitmaps member function), the “check mark on” bitmap is displayed.

  • MF_DISABLED   Disables the menu item so that it cannot be selected but does not dim it.

  • MF_ENABLED   Enables the menu item so that it can be selected and restores it from its dimmed state. Note that the value of this constant is 0; an application should not test against 0 for failure when using this value.

  • MF_GRAYED   Disables the menu item so that it cannot be selected and dims it.

  • MF_MENUBARBREAK   Places the item on a new line in static menus or in a new column in pop-up menus. The new pop-up menu column will be separated from the old column by a vertical dividing line.

  • MF_MENUBREAK   Places the item on a new line in static menus or in a new column in pop-up menus. No dividing line is placed between the columns.

  • MF_SEPARATOR   Draws a horizontal dividing line. Can only be used in a pop-up menu. This line cannot be dimmed, disabled, or highlighted. Other parameters are ignored.

  • MF_UNCHECKED   Acts as a toggle with MF_CHECKED to remove a check mark next to the item. When the application supplies check-mark bitmaps (see the SetMenuItemBitmaps member function), the “check mark off” bitmap is displayed. Note that the value of this constant is 0; an application should not test against 0 for failure when using this value.

Parameters

nID

Specifies the menu item ID, as determined by nFlags.

nFlags

Specifies the nature of nID. It can be one of the following values:

  • MF_BYCOMMAND   Specifies that the parameter gives the command ID of the existing menu item. This is the default.

  • MF_BYPOSITION   Specifies that the parameter gives the position of the existing menu item. The first item is at position 0.

Remarks

Returns the status of the specified menu item or the number of items in a pop-up menu.

Example

// CMainFrame::OnToggleTestMenuItem() is a menu command handler for
// "Test" menu item (whose resource id is ID_HELP_TEST). It toggles
// the checked or unchecked state of the "Test" menu item.
// CMainFrame is a CFrameWnd-derived class.

void CMainFrame::OnToggleTestMenuItem()
{
   // Get the popup menu which contains the "Test" menu item.
   CMenu* mmenu = GetMenu();
   CMenu* submenu = mmenu->GetSubMenu(3);

   // Check the state of the "Test" menu item. Check the menu item
   // if it is currently unchecked. Otherwise, uncheck the menu item
   // if it is not currently checked.
   UINT state = submenu->GetMenuState(ID_HELP_TEST, MF_BYCOMMAND);
   ASSERT(state != 0xFFFFFFFF);

   if (state & MF_CHECKED)
      submenu->CheckMenuItem(ID_HELP_TEST, MF_UNCHECKED | MF_BYCOMMAND);
   else
      submenu->CheckMenuItem(ID_HELP_TEST, MF_CHECKED | MF_BYCOMMAND);
}

CMenu OverviewClass MembersHierarchy Chart

See Also   , CMenu::CheckMenuItem, CMenu::EnableMenuItem