开发者

Getting the width of the icon area of a context menu

I need to get the width of the icon area of a context menu using the Windows API (>= Windows XP if this matters). What I mean by icon area you can see in this question, there is an image. It is a space res开发者_Python百科erved for icons on the left side of the menu.

I scanned through the wealth of information you can get via SystemParametersInfo and GetSystemMetrics, but found nothing. But there has to be some default value, right? How could I get it?


A native win32 menu does not really support icons so you can't really call it the icon area. In a basic menu the size of that area is SM_CXMENUCHECK wide (Plus SM_CXEDGE for padding probably) For Vista+ you might be able to find some better metrics with the MENU_POPUP* constants and GetThemeInt. AFAIK the exact layout and border constants required to replicate classic Win95+ menus are not documented.

Since you are talking about icons I assume you want to add icons to your menu so your width should probably be max(yourIconWidth,GetSystemMetrics(SM_CXMENUCHECK)) + padding. This old MSJ article is probably the best menu owner draw tutorial out there, and codeproject has its own menu article section with several different owner draw implementations. (MS Office and Visual Studio use custom stuff as well)

As a final note, since you said XP+ you should be able to use HBMMENU_CALLBACK and only worry about the icon and not the rest of the menu drawing...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜