Once Windows
has determined the height and width of a given menu item, it sends
WM_DRAWITEM message. Its first parameter again is the control
identifier (0 for menus) and the second one points to DRAWITEMSTRUCT
type.
Public Type
DRAWITEMSTRUCT
CtlType
As Long
CtlID As Long
itemID As Long
itemAction As Long
itemState As Long
hwndItem As Long
hdc As Long
rcItem As RECT
itemData As Long
End Type
What we need
to do now, is draw the menu item into the DC specified by hdc
member of DRAWITEMSTRUCT and in the location pointed by rcItem
(you cannot draw outside this rectangle, if you do - it will be
clipped). itemState member contains the current state of the item
(checked, highlighted and so on - we only care whether ODS_HIGHLIGHTED
bit is raised). So we check what itemData is (the number of the
menu item) and then accordingly to itemState, copy an image from
a picturebox into hdc using BitBlt.
Having processed
the message, return True (MyWndProc = 1).