如何在MFC中获取子菜单? [英] How to Get Submenu in MFC?

查看:354
本文介绍了如何在MFC中获取子菜单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获取一个子菜单,以便可以在它显示之前对其进行更改.

I'm trying to get a submenu so that I can make changes to it before it is displayed.

因此,我为窗口创建了OnInitMenu()处理程序.而且我计划使用pMenu->GetMenuItemInfo()来获取子菜单.

So I created an OnInitMenu() handler for my window. And I had planned to use pMenu->GetMenuItemInfo() to get the submenu.

但是,似乎没有用.为了找到所需的菜单,我必须提供菜单命令ID(对于硬编码项目位置,我认为它不令人满意).但是打开子菜单的菜单项没有命令ID.我可以获得该子菜单中存在的菜单命令,但随后我仍然没有菜单本身.

However, it doesn't appear this will work. In order to locate the menu I want, I must supply the menu command ID (I do not consider it satisfactory to hard code item positions). But menu items that open submenus do not have command IDs. I can get a menu command that exists inside that submenu, but then I still don't have the menu itself.

如何在不依赖MF_BYPOSITION的情况下找到嵌套在主菜单中的子菜单?

How can I locate a submenu nested in my main menu, without relying on MF_BYPOSITION?

推荐答案

看来答案是你做不到.使用命令ID定位菜单命令非常有意义,因为当您重新排列菜单项时,此类代码将继续起作用.但是,属于子菜单的菜单项根本没有命令ID.

It appears the answer is that you can't. Using command IDs to locate a menu command makes great sense because such code will continue to work as you rearrange menu items. However, menu items that are sub menus simply do not have a command ID.

一种方法是拥有一个已知的菜单命令,您可以通过ID搜索该命令,然后在该命令旁边插入新项目.但是,您仍然需要包含菜单.

One approach is to have a known menu command, which you can search for by ID, and then insert new items next to that command. However, you still need the containing menu.

我最终使用的方法是研究MFC用来填充文件"菜单中的"最近使用"文件列表的代码的结果.过时的 Paul DiLascia的Q& 《 Microsoft Systems Journal》中的一列.

The approach I ended up using resulted from studying the code MFC uses to populate the most recently used file list in the File menu. The general technique is described in the somewhat dated Paul DiLascia's Q & A column from Microsoft Systems Journal.

这篇关于如何在MFC中获取子菜单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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