在 Windows API 中设置菜单的宽度 [英] Setting the width of a menu in the Windows API

查看:65
本文介绍了在 Windows API 中设置菜单的宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 wxWidgets 中创建一个自定义控件,它显示一个菜单作为它的一部分,目前正在 Windows 方面工作.wxWidgets 没有设置菜单宽度的方法.它只是使窗口与最长的字符串一样宽,再加上两边的几个像素.

I'm creating a custom control in wxWidgets that displays a menu as part of it, and currently working on the Windows side of things. wxWidgets doesn't have a way of setting the width of a menu. It just makes the window as wide as the longest string plus a few pixels on either side.

在 API 中,有一种方法可以获取实际的 Windows API 菜单句柄.除了根据字符串的宽度自行计算之外,Windows API 是否有设置菜单宽度的方法?

In the API, there is a way to get the actual Windows API menu handle. Does the Windows API have a method of setting the width of a menu other than just calculating it on its own based on the width of the string?

推荐答案

通过菜单句柄,可以循环菜单项,调用SetMenuItemInfo,表示要对菜单项进行自绘.执行此操作时,附加菜单的窗口将收到 WM_MEASUREITEM 消息,然后您将通过设置菜单所需的尺寸来响应该消息.您可以在此处设置宽度.

With the handle of the menu, you can cycle through the menu items and call SetMenuItemInfo, indicating that you want to owner-draw the menu items. When you do this, the window that the menu is attached to will receive the WM_MEASUREITEM message, which you would then respond to by setting the dimensions required for the menu. It is here you can set your width.

当然,这意味着您必须为包含菜单的窗口子类化 windows 消息处理程序.

Of course, this means you have to subclass the windows message handler for the window that contains the menu.

这篇关于在 Windows API 中设置菜单的宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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