Click here to Skip to main content
15,889,879 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
if the user entered password is correct, the submenu item should be automatically updated by checkmark. So please help me in that.

What I have tried:

UINT CheckMenuItem(UINT m_nAllowEditing, _ID_EDIT_ALLOWEDITING | MF_CHECKED);
Posted
Updated 3-Oct-16 23:36pm
Comments
enhzflep 4-Oct-16 4:44am    
Right, and what happened when you used CheckMenuItem according to the documentation?
CMenu::CheckMenuItem

1 solution

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->Enable(m_nAllowEdtining);
    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().
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900