Shoutbox

[PROBLEM] Icons in menu have black backgrounds on XP - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: [PROBLEM] Icons in menu have black backgrounds on XP (/showthread.php?tid=80685)

[PROBLEM] Icons in menu have black backgrounds on XP by Matti on 01-04-2008 at 04:04 PM

Hi,

I faced this problem already some time ago during Countdown Live 2 development, but I thought it was simply caused by my terrible coding. Maybe it is caused by it, but after so many revisions I think there has to be something else with this...

This is what my script does:

  1. I create a popup menu with CreatePopupMenu.
  2. I add a string menu item to it with AppendMenu.
  3. I create a HBITMAP from an image:
    1. I create a GDI+ Bitmap object from an image file (in my case, "test.gif") using GdipCreateBitmapFromFile.
    2. I create a HBITMAP from the Bitmap object using GdipCreateHBITMAPFromBitmap with 0xFF000000 0x00000000 as background parameter (totally transparent, according to Matty Matty made a mistake, PLSC updated).
  4. I add the HBITMAP to the menu item:
    1. I create a partial MENUITEMINFO structure with the cbSize, fMask and hbmpItem members set.
    2. I use SetMenuItemInfo to assign this structure to the menu item.
  5. I let the menu pop up when the user clicks on a button using TrackPopupMenu.
This works great! I can have beautiful icons next to my menu items, I even made a whole class which simplifies this process. I was so excited about this until... I sent it to my testers. First response: cool, but the menu item icons have a black background. The cause? I run Vista, my testers have XP. One of my testers also runs Vista and he confirmed that it works on his Vista PC, but not on his XP system.
I received this screenshot from one of my XP testers: (cropped)
[Image: menu-icon-problem.png]
I have spent hours trying to figure out why this was happening, but I couldn't find anything. Finally, I gave up and added a Windows version check so that the images would only be added on Vista or higher.

Since then, I periodically gave this problem another attempt to solve it, but today I decided to stop waisting time on it for much longer. I attached an example script of this problem, and if someone can find the missing link and fix this on XP... please, share your discoveries! :)
RE: [PROBLEM] Icons in menu have black backgrounds on XP by phalanxii on 01-05-2008 at 06:10 AM

From my experimenting, it seems that only the blue component of your background parameter affects the background. Changing it to 0x000000FF yields a bright blue, and values in between (like 0x0000007F) produce dark blues. The alpha, red and green channels seem to be ignored and taken as 0.

I don't know whether it's a problem with your image or a bug with GDI+, but I found some links for you of other people having the same problem: [1] and [2].


RE: [PROBLEM] Icons in menu have black backgrounds on XP by Matti on 01-05-2008 at 11:19 AM

Aww... you're giving me headaches, phalanxii! :P
Unfortunately, I can't do testing myself as all PCs here at home are upgraded to Vista.

So, from what I understand, there are problems with converting a GDI+ Bitmap to a HBITMAP. But, let's say that instead of preserving transparency, would it be easier to create a color mask and create transparency by filtering out one color? Would that solve the need of using GDI+ Bitmaps? Would it be possible in fact? :P

UPDATE: Okay, markee and NanaFreak use exactly the same function for their Web2Live script to add new signatures to the list. They modify the image list and it works great. I try to add it to a menu item and it fails. So, maybe it's not the bitmap loading, but the bitmap drawing... I guess that we'll have to look at the 4th step, namely the the SetMenuItemInfo part. Any known issues with that bit? ^o)

UPDATE 2: Hmm... this looks like an interesting MSDN article: Vista Style Menus. It looks like it's really caused by the menus! :O

After a read, I think it's clear to me that Vista causes the icons to work, while lower versions don't support it. Maybe an owner-draw could fix it... but I doubt Plus! scripts can actually handle those! :(


Therefore, I'd like to submit a request to Patchou:
  • Make the menus of MenuButtonControls editable in run-time. Something like PlusWnd::MenuButton_SetMenu(CtrlId, MenuXML) would be great! :)
  • Add some kind of support for images in menus. Plus! already does an owner-draw on the menu, so why can't you use that to draw images on it? You already did so with ComboBoxControls! ;)