CMFCMenuButton无法关闭 [英] CMFCMenuButton does not close

查看:106
本文介绍了CMFCMenuButton无法关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个CDialog和一个CFMCMenuButton.当我打开它时,一切正常显示:

I have a CDialog with a CFMCMenuButton. when I open it, everything appears normally:

当我单击其他位置以关闭菜单时,会发生问题.菜单似乎无法关闭,除非用户选择它的一个选项.而且,如果我按键盘上的Escape键,则对话框会自行关闭,这太过激烈了.我真的希望它仅关闭菜单.

The problem happens when I click somewhere else to close the menu. The menu seems unclosable, unless user selects an option of it. And if I press Escape on the keyboard, the dialog closes itself, which is too drastic; I really would want it to close only the menu.

我知道我可以通过将资源文件中其属性"OS Menu"设置为True(或等效地,分配其属性m_bOSMenu= TRUE)来解决此问题.我会得到:

I know I could solve this by setting its property "OS Menu" in the resource file to True (or equivalently, assigning its property m_bOSMenu= TRUE). And I would get:

如您在图像中所见,后果是:

As you can see in the image, the consequences are :

  • 我松开了图标(不是很重要)
  • 我放松了一些由OnInitMenuPopup完成的项目的禁用(重要)(注意:第二个菜单列也由OnInitMenuPopup完成,并且它应该看起来应该是正确的).如果用户单击这些选项,它们将起作用,并且不应.
  • I loose the icons (not very important)
  • I loose some items' disablings (important) done by OnInitMenuPopup (side note: the second menucolumn is also done by OnInitMenuPopup and it appears as it should be). If user clicks in these options, they will work and they SHOULD NOT.

我该如何解决问题?

推荐答案

答案直接来自MFC源.

The answer comes from straight from the MFC source.

函数CMFCMenuButton::OnShowMenu中的文件afxmenubutton.cpp建议使用CDialogEx而不是CDialog:

The file afxmenubutton.cpp in its CMFCMenuButton::OnShowMenu function advises to use a CDialogEx instead of a CDialog:

#ifdef _DEBUG
    if ((pParent->IsKindOf(RUNTIME_CLASS(CDialog))) && (!pParent->IsKindOf(RUNTIME_CLASS(CDialogEx))))
    {
        TRACE(_T("CMFCMenuButton parent is CDialog, should be CDialogEx for popup menu handling to work correctly.\n"));
    }
#endif

然后,我将对话框类更改为从CDialogEx派生,现在一切正常!将OS菜单属性设置为False,将显示图标,并且禁用的选项实际上被禁用并显示为灰色!

Then I changed my dialog class to derive from CDialogEx, and now everything works perfectly! Having the OS Menu property as False, icons are shown and the disabled options are really disabled and grayed out!

更新: https://上的一些文档msdn.microsoft.com/en-us/library/Bb983913.aspx

这篇关于CMFCMenuButton无法关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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