我想在MFC中输入的密码正确时更新我的​​子菜单项。 [英] I want to update my submenu item as checked when the password entered is correct in MFC.

查看:58
本文介绍了我想在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 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().


这篇关于我想在MFC中输入的密码正确时更新我的​​子菜单项。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆