Condividi tramite


CMenu::GetMenuItemInfo

Recupera informazioni su una voce di menu.

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

Parametri

  • uItem
    Identificatore o posizione della voce di menu per ottenere informazioni su.Il significato di questo parametro dipende dal valore ByPos.

  • lpMenuItemInfo
    Un puntatore a MENUITEMINFO, come descritto in Windows SDK, che contiene informazioni sul menu.

  • fByPos
    Valore che specifica il significato nIDItem.Per impostazione predefinita, ByPos è FALSE, che indica che il uItem è un identificatore voce di menu.Se ByPos non è impostata su FALSE, indica una posizione voce di menu.

Valore restituito

Se la funzione ha esito positivo, il valore restituito è diverso da zero.Se la funzione ha esito negativo, il valore restituito è zero.Per ottenere informazioni dettagliate sugli errori, utilizzare la funzione Win32 GetLastError, come descritto in Windows SDK.

Note

Questa funzione membro implementa il comportamento della funzione Win32 GetMenuItemInfo, come descritto in Windows SDK.Si noti che nell'implementazione GetMenuItemInfo, è MFC non utilizzano un handle a un menu.

Esempio

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

Requisiti

Header: afxwin.h

Vedere anche

Riferimenti

Classe di CMenu

Grafico della gerarchia

CWnd::GetMenu

CMenu::GetMenuItemCount

CMenu::GetMenuItemID