0

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 reserved 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?

Community
  • 1
  • 1
Heinrich Ulbricht
  • 10,064
  • 4
  • 54
  • 85

1 Answers1

2

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...

Anders
  • 97,548
  • 12
  • 110
  • 164
  • 1
    If you want those fancy icon menus your best bet is probably two implementations; HBMMENU_CALLBACK or full owner draw on NT5 and using the new 32bit (pre multiplied alpha) menu bitmap support on NT6+ – Anders Apr 29 '11 at 10:47
  • Anders, thanks for the tips. I just need to measure the width to do some positioning in a special case. So no drawing involved. The theming stuff is interesting, I experimented a bit. Seems like my best bet (on Vista+) would be something like MENU_POPUPBORDERS+MENU_POPUPCHECK+MENU_POPUPGUTTER+MENU_POPUPSEPARATOR for the width. But the border seems to change depending on the image size. The more I think about it the more appealing seems to just estimate the size. – Heinrich Ulbricht Apr 29 '11 at 11:39