I thought of being clever, and tried changing the BG colour of the whole menu [Light Grey] and have the ImageBG be Same Colour, but it seems changing the colour only affects the Menu area and not the Icon Drawn area, very weird :/
Any idea on applying the colour there too ?
[attached image has an Orange BG for demo purposes]
_____________________________________________________________________
----If this post has helped you. Please take time to Rate it.
----If you've solved your problem, then please mark it as RESOLVED from Thread Tools.
On Vista+, a 32bpp premultiplied alpha bitmap can be used and should work well only if window is themed.
For all other cases, the best solution is to draw the image yourself. With Comctl32's subclassing APIs, this may not be very painful any longer. If that idea seems like exploring, search forum for subclassing keyword: SetWindowSubclass. Now you'll need to let Windows know you want to draw the bitmap. The SetMenuItemInfo API would be called for each menuitem you want to custom draw the image. With the associated MenuItemInfo structure, you would set the fMask to MIIM_BITMAP and the hbmpItem member to -1. Per MSDN, doing this requires you to trap 2 messages which would give you the info needed to render the image. See those two msdn links for more info.
Insomnia is just a byproduct of, "It can't be done"
32bpp bitmaps with transparency work OK via LoadPicture.
However, LoadResPicture on the same image loses the transparency.
You can store the Bitmap as "Custom" resource, use LoadResData, and use IStream to avoid using a temp file.
Tested with Themes enabled (Vb6.exe with Manifest).
Sample code attached.
Last edited by DrUnicode; Oct 21st, 2014 at 11:09 PM.
On Vista+, a 32bpp premultiplied alpha bitmap can be used and should work well only if window is themed.
So, even this version has it's limits? WinXP Machine + Themed Windows.
BTW, any straight way on converting PNGs to 32bpp Bitmaps? It seems in Photoshop i need to create a new ALPHA Channel every time.
_____________________________________________________________________
----If this post has helped you. Please take time to Rate it.
----If you've solved your problem, then please mark it as RESOLVED from Thread Tools.
straight way of converting png to 32bpp? 3rd party tools?
edited: The important thing here is that the bmp be stored as premultiplied rgb components else image used with SetMenuItemInfo or SetMenuItemBitmaps won't work right
In VB one method would look like this, using GDI+
1) Start GDI+ of course
2) Load png into GDI+ image
3) Create a GDI (not GDI+) 32bpp DIB section same target size of destination bmp (say 16x16 for example)
4) Create an offscreen device context & select DIB section into it
5) Use GDI+ to render the GDI+ image, scaled as needed, to the GDI hDC
6) Clean up: destroy GDI+ image & shut GDI+ down. Unselect DIB, destroy DC, save DIB to disk & destroy DIB
The reason why we want GDI+ to render the PNG to DIB section is that when GDI+ sees a 32bpp GDI target DC/image, it premultiplies the rgb components in relation to the alpha. That's what these APIs on Vista+ are looking for.
Note: Even the old SetMenuItemBitmaps works with these premultiplied bitmaps on Vista
Code:
AppendMenu hMenu, MF_STRING, 110, "Some Menu Item"
hbmp = LoadImage(0, "c:\testimages\mnubmp.bmp", 0, 32, 32, LR_CREATEDIBSECTION Or LR_LOADFROMFILE)
SetMenuItemBitmaps hMenu, 110, 0, hbmp, hbmp
' after menu is closed: DeleteObject hBmp
The 6 steps I listed above are an outline. There are several GDI/GDI+ related calls in between those steps.
It may be overkill for what you want, but you could play with my AlphaImage Control (linked in my signature below). That project would do it all for you in a few steps as shown below. If you're looking for something to quickly convert png to 32bpp premultiplied bitmaps, then think it'd take you 15 minutes to whip up a simple: "Select Png File, Convert, Save To Destination" type of project, so it can be used over & over again as needed.
1) Add new alpha image control to a form
2) Add a command button & this code in the Click event
3) Ensure form's project is the startup project. Run project & click button
Code:
Dim SS As SAVESTRUCT
Set AlphaImgCtl1.Picture = LoadPictureGDIplus("myMenuImage.png")
SS.ColorDepth = lvicConvert_TrueColor32bpp_pARGB
SS.Height = 32: SS.Width = 32 ' << change as desired or remove line if saving original size
SavePictureGDIplus AlphaImgCtl1.Picture, "C:\testimages\mnuBmp.bmp", lvicSaveAsBitmap
Last edited by LaVolpe; Oct 22nd, 2014 at 07:52 PM.
Insomnia is just a byproduct of, "It can't be done"