[英]Problems with CMenu::ModifyMenu
I'm using CMenu::ModifyMenu in the OnCreate method of my CFrameWnd derived class to change the captions on my menu to match the user language. 我在CFrameWnd派生类的OnCreate方法中使用CMenu :: ModifyMenu更改菜单上的标题以匹配用户语言。
I'm using VC++ designer and the menu is declared in a .rc file. 我正在使用VC ++设计器,并且菜单在.rc文件中声明。
For the MENUITEM elements I use it as follow: 对于MENUITEM元素,我按如下方式使用它:
m_wndMenu->ModifyMenu(ID_APP_EXIT, MF_BYCOMMAND, NULL, CString((LPWSTR) ID_APP_EXIT));
For the POPUP elements (that don't have an ID) I use it as follow: 对于POPUP元素(没有ID),我按如下方式使用它:
m_wndMenu->ModifyMenu(0, MF_BYPOSITION | MF_STRING, NULL, CString((LPWSTR) ID_MENU_POPUP_FILE));
It works as expected to change the captions, but for the menu items that are initialy disabled when I change the caption they get enabled. 它可以按预期的方式更改字幕,但是对于我最初更改其标题时被禁用的菜单项,它们将被启用。 How do I fix this?
我该如何解决?
You may have to explicitly disable the menu item and set tool tip text after a call to ModifyMenu
. 在调用
ModifyMenu
之后,您可能必须显式禁用菜单项并设置工具提示文本。 Using ModifyMenu
will effectively destroy the previous menu item and create a new one. 使用
ModifyMenu
将有效地破坏前一个菜单项并创建一个新菜单项。 You are losing any settings and initialization from the resource file or otherwise that you had on the previous item or menu. 您将丢失资源文件中的任何设置和初始化,否则将丢失上一项或菜单中的设置和初始化。
See remarks: http://msdn.microsoft.com/en-us/library/4tbfebs6(v=vs.80).aspx 查看备注: http : //msdn.microsoft.com/zh-cn/library/4tbfebs6( v= vs.80).aspx
for such scenario, better to use EnableMenuItem function, like this m_wndMenu->EnableMenuItem(ID_APP_EXIT, MF_BYCOMMAND| MF_ENABLED); 对于这种情况,最好使用EnableMenuItem函数,例如m_wndMenu-> EnableMenuItem(ID_APP_EXIT,MF_BYCOMMAND | MF_ENABLED);
this will work... 这将工作...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.