AppendMenu使用时的一个诡异问题?

10 篇文章 0 订阅

1、问题背景

自定义右键菜单列表,使用AppendMenu进行子条目的插入操作。

2、问题现象

大部分情况下,右键菜单项正常显示。极少情况下,出现某个或者某几个菜单项后面多出来了子菜单列表。
出现这种情况,没有固定的时间地点,没有固定的流程或者操作,没有确定的操作系统。出现或者不出现一切皆随缘。

3、问题代码
HMENU rightMenu=CreatePopupMenu();
HMENU popup = CreatePopupMenu();
#define IDM_MENU_TEST    1001
AppendMenu(rightMenu, MF_POPUP | MF_STRING, (UINT_PTR)IDM_MENU_TEST,  L"Test Menu");//当第二个参数为MF_POPUP时需要设置第三个参数为子菜单项的句柄。
4、问题原因

AppendMenu第二个参数为MF_POPUP,需要将第三个参数设置为菜单项的句柄,而不是菜单ID。

5、参数说明
Parameters
hMenu
[in] Handle to the menu bar, drop-down menu, submenu, or shortcut menu to be changed.
uFlags
[in] Specifies flags to control the appearance and behavior of the new menu item. This parameter must be a combination of the values listed in Menus Constants.

If this parameter includes the MF_SEPARATOR constant, AppendMenu ignores the values of the lpNewItem and uIDNewItem parameters. If this parameter includes the MF_STRING constant, the lpNewItem parameter points to the string.

uIDNewItem
[in] Either the identifier of the new menu item or, if the uFlags parameter is set to MF_POPUP, the handle to the drop-down menu or submenu.
lpNewItem
[in] Long pointer to the content of the new menu item. If uFlags includes the MF_STRING constant, lpNewItem points to a null-terminated string (the default). If uFlags includes the MF_OWNERDRAW constant, lpNewItem points to a 32-bit value that can be used to maintain additional data related to the menu item.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值