我想在MFC中输入的密码正确时更新我的子菜单项。 [英] I want to update my submenu item as checked when the password entered is correct in MFC.
问题描述
如果用户输入的密码正确,则应通过复选标记自动更新子菜单项。所以请帮助我。
我尝试过:
UINT CheckMenuItem(UINT m_nAllowEditing,_ID_EDIT_ALLOWEDITING | MF_CHECKED);
CheckMenuItem
是CMenu
类函数。所以你需要一个指针菜单。
如果项目在主菜单的子菜单中,你可以在中使用MFC命令处理改为CDocument
派生类:
ON_UPDATE_COMMAND_UI(ID_OF_THE_MENU_ITEM,OnUpdateAllowEditing)
void CMyDoc :: OnUpdateAllowEditing(CCmdUI * pCmdUI)
{
// pCmdUI-> Enable(m_nAllowEdtining);
pCmdUI-> SetCheck(m_nAllowEdtining);
}
这是首选方法,因为您不必检索指向主菜单的指针,该指针可能是不同类型的(CMenu
或CMFCMenuBar
)。
如果该项目是动态创建的菜单(例如弹出窗口或上下文菜单)您可能已经存储了指向该菜单的指针。然后调用GetSubMenu(0)
获取指向子菜单的指针,然后可以用它来调用CheckMenuItem()
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);
CheckMenuItem
is aCMenu
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 yourCDocument
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
orCMFCMenuBar
).
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 callGetSubMenu(0)
to get a pointer to the sub menu which can then be used to callCheckMenuItem()
.
这篇关于我想在MFC中输入的密码正确时更新我的子菜单项。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!