如何动态更改应用程序中的主菜单? [英] How do I change main menu in application dynamically?

查看:140
本文介绍了如何动态更改应用程序中的主菜单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我有一个使用VC ++版本6和MFC的应用程序,并且想根据用户选择更改主菜单.最好的方法是什么?有例子吗?

谢谢
Neil

Hi,
I have an application using VC++ version 6, with MFC, and would like to change the main menu depending on user selection. What is the best way doing this? Any examples?

Thanks
Neil

推荐答案

我认为最好的方法是用所有可能的选项填充菜单,并根据用户选择设置其可见性.
I think the best way is to populate a menu with all possible options, and set their visibility based on the user selection.


我的经验是,用户在使用该程序时控件(或菜单项)出现或消失时不喜欢它.最多来说,他们只是对禁用物品感到不舒服,但是当事情开始消失/重新出现时,它们会发疯.如果您是我,我会重新考虑自己的界面.
My experience is that users don''t like it when controls (or menu items) appear and disappear while they''re using the program. At the very most, they are just barely comfortable with items being disabled, but when things start disappearing/reappearing, they freak out. I''d rethink my interface if I were you.


如果您的目标是在编译时更改菜单,最好的方法是使用资源编辑器,对所有它们使用相同的 ID ,并使用它们的 Condition 属性(您可以在属性窗口).

这样,资源编辑器会根据您放入的资源编译器预处理器宏,生成具有#ifdefrc文件,该文件带有编译或不编译菜单所需的#ifdef 条件属性.

请注意,资源编译器使用的预处理器宏与 C/C ++编译器使用的预处理器宏不同:您应该在资源项目属性的标签.
If your target is to change the menu at compile time, the best is to create your menus with the resource editor, using the same ID for all of them, and using the Condition property of them (you find the Condition property on the Property window).

This way the resource editor generates an rc file with the #ifdef required to compile or not your menus depending on the resource compiler pre-processor macro that you put inside the Condition property.

Note that the pre-processor macro used by the resource compiler are not the same that the C/C++ compiler uses: you should define them on the Resource tab of your project properties.


这篇关于如何动态更改应用程序中的主菜单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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