将下拉菜单按钮添加到 CMFCToolbar
我正在尝试向 CMFCToolbar 添加菜单。按照我在网上找到的建议,我这样做:
CMenu m_Menu;
m_Menu.LoadMenu(IDR_MYMENU);
m_Toolbar.ReplaceButton ( ID_DOTHISWHENCLICKED,
CMFCToolBarMenuButton( ID_DOTHISWHENCLICKED,
m_Menu,
10,
nullptr,
FALSE));
所以上面给了我一个带有下拉箭头的按钮。当我单击该按钮时,它会执行 ID_DOTHISWHENCLICKED
操作。当我单击下拉箭头时,我会看到一个包含一项的菜单。该项目的标题是IDR_MYMENU
,它有一个子菜单,这是我想要显示的菜单。像这样的东西:
[BUTTON]
我的菜单
Submenu Item 1
Submenu Item 2
Submenu Item 3
显然我想看到的是:
[BUTTON]
子菜单项 1
子菜单项 2
子菜单项 3
所以我的问题是....为什么不是 中的所有菜单项IDR_MYMENU
在菜单中,而不是在子菜单中吗?
谢谢。
I'm trying to add a menu to a CMFCToolbar. Following advice I found online, I'm doing it like this:
CMenu m_Menu;
m_Menu.LoadMenu(IDR_MYMENU);
m_Toolbar.ReplaceButton ( ID_DOTHISWHENCLICKED,
CMFCToolBarMenuButton( ID_DOTHISWHENCLICKED,
m_Menu,
10,
nullptr,
FALSE));
So the above gives me a button with a drop-down arrow. When I click the button, it does the action ID_DOTHISWHENCLICKED
. When I click the drop-down arrow, I get a menu with one item in it. The item is the title of IDR_MYMENU
and this has a sub-menu that is the menu I would like to be displayed. Something like this:
[BUTTON]
My Menu
Submenu Item 1
Submenu Item 2
Submenu Item 3
Obviously what I want to see is:
[BUTTON]
Submenu Item 1
Submenu Item 2
Submenu Item 3
So my question is.... why aren't all of the menu items in IDR_MYMENU
in the menu, instead of being in a sub-menu off of it?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只需在创建菜单按钮时传入
.GetSubMenu(0)->GetSafeHmenu()
(而不是有问题的CMenu
)即可解决此问题。为什么会这样对我来说完全是个谜,如果您知道的话,这也是您知道的 MFC 主义之一。不确定是否删除此问题或勾选已解决以防其他人遇到此问题。
This problem is fixed simply by passing in
.GetSubMenu(0)->GetSafeHmenu()
, instead of theCMenu
in question, when creating the menu button. Why this should be so is a complete mystery to me, and one of those MFC'isms that you know if you know.Not sure whether to delete this question or tick it solved in case anyone else ever has this issue.