Setting the width of a menu in the Windows API

时光毁灭记忆、已成空白 提交于 2019-12-20 06:25:35

问题


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.

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?


回答1:


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.

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




回答2:


First of all, try to obtain the HWND to the menu: (1) WM_DRAWITEM (2)get the HDC (3)WindowFromDC(), then you can arbitrarily adjust aspects of the menu. NOTE: don't send WM_QUIT WM_CLOSE to the menu, or you'll effectively shut down your computer with no clue.




回答3:


It has nothing to do with WM_MEASUREITEM

Just use internal win32 menu messages

(Win32 FAQ : news://comp.os.ms-windows.programmer.win32)



来源:https://stackoverflow.com/questions/518910/setting-the-width-of-a-menu-in-the-windows-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!