I'm trying to change the default bitmap on a menu item. Unfortunately, I'm not getting it to work.
CodePudding user response:
You need the HMENU
handle of the menu that the red
item directly belongs to. You are using the top-level HMENU
, but red
is a child item of the sub-menu of the color
item, which is a child item of the sub-menu of the Menu
item, which is a child item of the top-level menu.
Once you have the top-level HMENU
, use GetSubMenu()
or GetMenuItemInfo()
to get the HMENU
of the sub-menu for the Menu
item, then use that handle to get the HMENU
of the sub-menu for the color
item, and then finally use that handle to set the bitmaps for the red
item.
Also, you are not checking whether LoadBitmap()
is returning NULL or not. Even if it is not, you are responsible for destroying the bitmaps when you are done using them. So, even if this code worked, you would be leaking resources.