如何使用MFC禁用和灰色顶级菜单项 [英] How can I disable and gray the top level menu item using MFC

查看:970
本文介绍了如何使用MFC禁用和灰色顶级菜单项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个对话框应用程序,其中我想在对话框的顶部有可点击的菜单项。这些项目不显示下拉菜单,但实际上运行相关命令。

I have a dialog application in which I want to have clickable menu items at the top of the dialog. These items do not show a drop down menu but actually run the associated commands.

我通过在对话框属性中设置Popup = False并分配消息id,我的问题是没有能力正确禁用项目,当它没有意义的项目是可点击(根据内部状态存储在对话框中)

I did this by setting Popup=False in the dialogs properties and assigning a message-id but my problem is not having the ability to disable the item properly when it makes no sense for the item to be clickable (depending on internal state stored in the dialog)

我有已经找到了如何从 http:// www。禁用任何弹出式菜单项。 microsoft.com/msj/0299/c/c0299.aspx ,但这不是我想要的

I have already found out how to disable any popup-parent menu items from http://www.microsoft.com/msj/0299/c/c0299.aspx, but this isn't exactly what I want

我还发现如何添加菜单命令从msdn知识库文章KB242577路由到对话框。

I have also found out how to add menu command routing to dialogs from the msdn knowledgebase article KB242577.

这对子菜单项工作正常,但不是顶级菜单。

This works fine for sub-menu items, but not for the top level menu.

我目前使用以下函数来禁用

I am currently using the following function to do the disabling

void CYourDlg::EnableMenuItem(UINT nCommand, BOOL bEnable)
{
   CMenu* pMenu = GetMenu();
   pMenu->EnableMenuItem(nCommand, bEnable ? 0 : MF_DISABLED | MF_GRAYED);
}

这一半工作,如果你离开应用程式

This half works, if you alt-tab away from the app it does show as disabled, otherwise it doesn't.

有没有办法以编程方式使区域无效?

Is there a way to invalidate the area programmatically?

推荐答案

我没有尝试过,但在常规窗口(非对话框) CWnd :: DrawMenuBar 应该做你想要的。它可能也适用于基于对话框的应用程序。

I have not tried but in regular window (not dialog) CWnd::DrawMenuBar should do what you want. It might work with dialog based applications as well.

void CYourDlg::EnableMenuItem(UINT nCommand, BOOL bEnable)
{
   CMenu* pMenu = GetMenu();
   pMenu->EnableMenuItem(nCommand, bEnable ? 0 : MF_DISABLED | MF_GRAYED);
   DrawMenuBar();
}

这篇关于如何使用MFC禁用和灰色顶级菜单项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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