BOOL CMenu::GetMenuItemInfo( UINT nIDItem, LPMENUITEMINFO lpMenuItemInfo, BOOL ByPos = FALSE );
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 Platform SDK.
Parameters
nIDItem
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 Platform SDK, that contains information about the menu.
ByPos
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.
Remarks
This member function implements the behavior of the of the Win32 function GetMenuItemInfo, as described in the Platform SDK.
Note that in the MFC implementation of GetMenuItemInfo, you do not use a handle to a 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.
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_HELP_TEST, &info));
if (info.fState & MF_CHECKED)
submenu->CheckMenuItem(ID_HELP_TEST, MF_UNCHECKED | MF_BYCOMMAND);
else
submenu->CheckMenuItem(ID_HELP_TEST, MF_CHECKED | MF_BYCOMMAND);
}
CMenu Overview | Class Members | Hierarchy Chart
See Also CWnd::GetMenu, CMenu::GetMenuItemCount, CMenu::GetMenuItemID