CMenu::GetMenuItemInfo

检索有关菜单项的信息。

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

参数

  • uItem
    菜单项获取信息的标识符或位置有关。 此参数的含义取决于 ByPos的值。

  • lpMenuItemInfo
    MENUITEMINFO的指针,如 Windows SDK所述,包含有关该菜单的信息。

  • fByPos
    指定 nIDItem的含义值。 默认情况下,ByPos 是 FALSE,指示uItem是菜单项标识符。 如果 ByPos 未设置为 FALSE,它显示一个菜单项的位置。

返回值

如果函数成功,则返回值是非零。 如果函数失败,则返回值为零。 若要扩展的错误信息,请使用Win32函数 GetLastError,如 Windows SDK所述。

备注

此成员函数实现行为Win32函数 GetMenuItemInfo,如 Windows SDK所述。 监视 GetMenuItemInfo的MFC实现,不要使用的句柄。菜单。

示例

// 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);
}

要求

Header: afxwin.h

请参见

参考

CMenu选件类

层次结构图

CWnd::GetMenu

CMenu::GetMenuItemCount

CMenu::GetMenuItemID