您的位置:首页 > 编程语言 > C语言/C++

visual C++ 2010 MFC 不收缩隐藏那些不经常使用的菜单项

2012-09-25 19:44 232 查看
最近写了个小程序,用MFC向导生成了一个单文档模板,后添添改改做的,但是菜单项老师隐藏了,这点很不爽,google了一下,没结果,很多人问,查询了下MSDN,发现:
Remarks

The CMFCMenuBar class is a menu bar that implements docking functionality. It resembles a toolbar, although it cannot be closed - it is always displayed.

CMFCMenuBar supports the option of displaying recently used menu item objects. If this option is enabled, the CMFCMenuBar displays only a subset of the available commands on first viewing. Thereafter, recently used commands are displayed together with the original
subset of commands. In addition, the user can always expand the menu to view all available commands. Thus, each available command is configured to display constantly, or to display only if it has been recently selected.

然后继续发现

A pop-up menu can hide rarely used commands if it has a parent button and the parent window is derived from the CMFCMenuBar Class. Use CMFCMenuBar::SetRecentlyUsedMenus to enable this feature and CMFCMenuBar::IsRecentlyUsedMenus to determine if this feature
is currently enabled. You must call both of these methods for the parent window.

心想,原来是这两个函数?果断在

m_wndMenuBar.SetPaneStyle(m_wndMenuBar.GetPaneStyle() | CBRS_SIZE_DYNAMIC | CBRS_TOOLTIPS | CBRS_FLYBY /* & ~ AFX_CBRS_AUTOHIDE*/ );

下面添加

m_wndMenuBar.SetRecentlyUsedMenus(FALSE);

m_wndMenuBar.SetShowAllCommands(TRUE);

这两行,发现运行了还是没效果呢,再朝下找找,发现

CList<UINT, UINT> lstBasicCommands;

lstBasicCommands.AddTail(ID_FILE_NEW);

lstBasicCommands.AddTail(ID_FILE_OPEN);

lstBasicCommands.AddTail(ID_FILE_SAVE);

lstBasicCommands.AddTail(ID_FILE_PRINT);

lstBasicCommands.AddTail(ID_APP_EXIT);

lstBasicCommands.AddTail(ID_EDIT_CUT);

lstBasicCommands.AddTail(ID_EDIT_PASTE);

lstBasicCommands.AddTail(ID_EDIT_UNDO);

lstBasicCommands.AddTail(ID_APP_ABOUT);

lstBasicCommands.AddTail(ID_VIEW_STATUS_BAR);

lstBasicCommands.AddTail(ID_VIEW_TOOLBAR);

lstBasicCommands.AddTail(ID_VIEW_APPLOOK_OFF_2003);

lstBasicCommands.AddTail(ID_VIEW_APPLOOK_VS_2005);

lstBasicCommands.AddTail(ID_VIEW_APPLOOK_OFF_2007_BLUE);

lstBasicCommands.AddTail(ID_VIEW_APPLOOK_OFF_2007_SILVER);

lstBasicCommands.AddTail(ID_VIEW_APPLOOK_OFF_2007_BLACK);

lstBasicCommands.AddTail(ID_VIEW_APPLOOK_OFF_2007_AQUA);

lstBasicCommands.AddTail(ID_VIEW_APPLOOK_WINDOWS_7);

CMFCToolBar::SetBasicCommands(lstBasicCommands);

而这些后面不就是默认自带的菜单项么,查询了下 CMFCToolBar::SetBasicCommands ,MSDN显示:

Sets the list of commands that are always displayed when a user opens a menu. //当用户打开菜单时,设置永久显示的菜单列表

A basic command is always displayed when the menu is opened. This method is meaningful when the user chooses to view recently used commands. //当菜单打开时,一个基本命令将一直显示。这个方法在用户选择查看最近使用过的命令的时候非常有意义。

Use the CMFCToolBar::AddBasicCommand method to add a command to the list of basic commands. Use the CMFCToolBar::GetBasicCommands method to retrieve the list of basic commands that is used by your application.

See the Explorer sample for an example that uses this method.

不太明白什么意思,大致上是说用来显示最近的命令,注释掉看看,发现菜单伸缩的那个按钮没有了,搞定!

http://hi.baidu.com/lostmind/item/443b7d12f6335b0fb98a1a85
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: