CMenu::GetMenuItemInfo

Retrieves information about a menu item.

BOOL GetMenuItemInfo(
   UINT uItem,
   LPMENUITEMINFO lpMenuItemInfo,
   BOOL fByPos = FALSE 
);

Parameters

  • uItem
    Identifier or position of the menu item to get information about. The meaning of this parameter depends on the value of ByPos.

  • lpMenuItemInfo
    A pointer to a MENUITEMINFO, as described in the Windows SDK, that contains information about the menu.

  • fByPos
    Value specifying the meaning of nIDItem. By default, ByPos is FALSE, which indicates that uItem is a menu item identifier. If ByPos is not set to FALSE, it indicates a menu item position.

Return Value

If the function succeeds, the return value is nonzero. If the function fails, the return value is zero. To get extended error information, use the Win32 function GetLastError, as described in the Windows SDK.

Remarks

This member function implements the behavior of the of the Win32 function GetMenuItemInfo, as described in the Windows SDK. Note that in the MFC implementation of GetMenuItemInfo, you do not use a handle to a menu.

Example

// CMainFrame::OnToggleTestMenuInfo() is a menu command handler for 
// "Toggle Info" menu item (whose resource id is ID_MENU_TOGGLEINFO). It 
// toggles the checked or unchecked state of the "Toggle Info" menu item.
// CMainFrame is a CFrameWnd-derived class.
void CMainFrame::OnToggleTestMenuItemInfo()
{
   // Get the popup menu which contains the "Toggle Info" menu item.
   CMenu* mmenu = GetMenu();
   CMenu* submenu = mmenu->GetSubMenu(4);

   // Check the state of the "Toggle Info" menu item. Check the menu item
   // if it is currently unchecked. Otherwise, uncheck the menu item
   // if it is not currently checked.
   MENUITEMINFO info;
   info.cbSize = sizeof (MENUITEMINFO); // must fill up this field
   info.fMask = MIIM_STATE;             // get the state of the menu item
   VERIFY(submenu->GetMenuItemInfo(ID_MENU_TOGGLEINFO, &info));

   if (info.fState & MF_CHECKED)
      submenu->CheckMenuItem(ID_MENU_TOGGLEINFO, MF_UNCHECKED | MF_BYCOMMAND);
   else
      submenu->CheckMenuItem(ID_MENU_TOGGLEINFO, MF_CHECKED | MF_BYCOMMAND);
}

Requirements

Header: afxwin.h

See Also

Concepts

CMenu Class

CMenu Members

Hierarchy Chart

CWnd::GetMenu

CMenu::GetMenuItemCount

CMenu::GetMenuItemID