CheckMenuItem
is a
CMenu
class function. So you need a pointer your menu.
If the item is inside a submenu of your main menu you can use the MFC command handling in your
CDocument
derived class instead:
ON_UPDATE_COMMAND_UI(ID_OF_THE_MENU_ITEM, OnUpdateAllowEditing)
void CMyDoc::OnUpdateAllowEditing(CCmdUI *pCmdUI)
{
pCmdUI->SetCheck(m_nAllowEdtining);
}
This is the preferred method because you don't have to retrieve a pointer to the main menu which may be of different types (
CMenu
or
CMFCMenuBar
).
If the item is part of a dynamically created menu (e.g. a popup or context menu) you have probably stored a pointer to that menu somewhere. Then call
GetSubMenu(0)
to get a pointer to the sub menu which can then be used to call
CheckMenuItem()
.