I am attempting to create an owner-drawn main menu, in Windows. I understand setting:
menuiteminfo.ftype = MFT_OWNERDRAW
I also know about handling the WM_MEASUREITEM and WM_DRAWITEM messages.
However, how do I know which main menu item is sending the message? (so that I can fill-in the appropriate box size and text) "itemID" seems to be the only unique identifier. But, how can I associate this pointer/handle to the item in question? I can use "lParam" to determine it is a menu item. But, I can't determine which menu item. "GetMenuItemID" is useless, as it returns "-1" for all main-menu items.
Or, am I going about this all-wrong? I have been searching for answers, for weeks. Really, all I want to do is change the text color of the main menu, from black, to white or light gray, so I can use a dark background.
The itemID
field of the MEASUREITEMSTRUCT
and DRAWITEMSTRUCT
structs tells you exactly which menu item is being measured/drawn. This is the ID that you specify when you create/modify a menu item. That ID is specified via either:
uIDNewItem
parameter of AppendMenu()
, InsertMenu()
, or ModifyMenu()
.item
parameter of InsertMenuItem()
or SetMenuItemInfo()
wID
field of the MENUITEMINFO
struct that you pass to InsertMenuItem()
or SetMenuItemInfo()
.Use whatever IDs you want, as long as they are unique for your menus.
You can also use the itemData
field of MEASUREITEMSTRUCT
and DRAWITEMSTRUCT
to receive any custom data you want for owner-drawn menu items, if you so desire (like, for example, a pointer to a buffer that contains a menu item's text string). This custom value can be anything you want that is meaningful for you. You set this value in the dwItemData
field of the MENUITEMINFO
struct that you pass to InsertMenuItem()
or SetMenuItemInfo()
.
This is all covered in the documentation: