Reputation: 21
I am trying to add icon image to context menu of my win32 application
Here is my code
hMenu = LoadMenuIndirect( LoadResourceLang( RT_MENU, resID ) );
hMenu = ::GetSubMenu( hMenu, 0 );
HBITMAP hBitmap = (HBITMAP)LoadImage((HMODULE)g_hInst,MAKEINTRESOURCE(IDB_BM_PAUSE), IMAGE_BITMAP, 16, 16, LR_CREATEDIBSECTION );
SetMenuItemBitmaps( hMenu, 2, MF_BITMAP|MF_BYPOSITION, hBitmap, hBitmap );
::TrackPopupMenu( hMenu, TPM_LEFTALIGN | TPM_LEFTBUTTON | TPM_RIGHTBUTTON, point.x, point.y, 0, m_hWnd, 0 );
Everything works fine when menu first shown.
But when the cursor hovers over menu item and selection rectangle is drawn, the bitmap is redrawn incorrectly, the transparency is ignored.
Here are the screenshots:
Any suggestion how to fix this?
Upvotes: 2
Views: 914
Reputation: 101569
These bitmaps are only supposed to be used for simple checkmarks etc. and must be monochrome bitmaps. Your usage seems fine as long as you only need one color.
The selected and clear bitmaps should be monochrome. The system uses the Boolean AND operator to combine bitmaps with the menu so that the white part becomes transparent and the black part becomes the menu-item color. If you use color bitmaps, the results may be undesirable.
Ideally you should generate the bitmap on the fly so it matches CYMENUCHECK.
On Windows Vista and later it is also possible to assign a 32bpp image to a menu item without doing owner-draw...
Upvotes: 3