What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » [?] Transparent bitmap in a pop-up menu

[?] Transparent bitmap in a pop-up menu
Author: Message:
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
32 / Male / Flag
Joined: Apr 2004
O.P. [?] Transparent bitmap in a pop-up menu
Okay, looking for some expert help here!

I have a right-click pop-up menu with some nifty features, but now I want to make it even nicer by placing images in front of the items. I can do this by loading a bitmap using LoadBitmap() and then use SetMenuItemBitmap() to set the bitmaps to the menu item. No problem at all to do this, the only problem is that the bitmaps aren't transparent. I know it has to be possible (how do the others do it else?) but I'm afraid my skills are just a tiny bit too less to do this. I guess I'll need to use GDI for this to make a certain color (like violet #FF00FF) transparent in the bitmap, so if anyone can help me with this, I'd really appreciate it! :)

This is what I use to place the bitmaps in the menu item at the moment:
code:
var hBitmapSrc = LoadBitmap(/* Path to file here */, 16, 16);
var MF_BYPOSITION = 0x400;
var Result = Interop.Call("user32", "SetMenuItemBitmaps", hMenu, i, MF_BYPOSITION, hBitmapSrc, hBitmapSrc); /* hMenu is the pop-up menu handle, i is the null-based item position */

function LoadBitmap(sPath, nWidth, nHeight) {
    var IMAGE_BITMAP = 0;
    var LR_LOADFROMFILE = 0x10;
    var LR_SHARED = 0x8000;
    var hInst = Interop.Call('kernel32', 'GetCurrentProcess');
    var hImage = Interop.Call('user32', 'LoadImageW', hInst, sPath, IMAGE_BITMAP, nWidth, nHeight, LR_LOADFROMFILE | LR_SHARED);
    return hImage;
}
Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
08-21-2007 07:14 PM
Profile E-Mail PM Web Find Quote Report
matty
Scripting Guru
*****


Posts: 8336
Reputation: 109
39 / Male / Flag
Joined: Dec 2002
Status: Away
RE: [?] Transparent bitmap in a pop-up menu
Straight from MSDN http://msdn2.microsoft.com/en-us/library/ms648045.aspx

fuLoad
    [in] This parameter can be one or more of the following values.

    LR_LOADTRANSPARENT
        Retrieves the color value of the first pixel in the image and replaces the corresponding entry in the color table with the default window color (COLOR_WINDOW). All pixels in the image that use that entry become the default window color. This value applies only to images that have corresponding color tables.

        Do not use this option if you are loading a bitmap with a color depth greater than 8bpp.

        If fuLoad includes both the LR_LOADTRANSPARENT and LR_LOADMAP3DCOLORS values, LRLOADTRANSPARENT takes precedence. However, the color table entry is replaced with COLOR_3DFACE rather than COLOR_WINDOW.

code:
LR_LOADTRANSPARENT 0x0020

This post was edited on 08-21-2007 at 07:24 PM by matty.
08-21-2007 07:22 PM
Profile E-Mail PM Find Quote Report
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
32 / Male / Flag
Joined: Apr 2004
O.P. RE: [?] Transparent bitmap in a pop-up menu
Thanks for that, matty. Unfortunately, it doesn't seem to work. The transparency isn't getting applied. I don't know if this is caused by the LoadImage function or by the fact I pass it to SetMenuItemInfo to set the bitmap... :-\

According to LoadImage, the pink should be replaced by the default window color (which is white #FFFFF). However, it doesn't do that. The bitmap is getting placed correctly in the menu but it isn't transparent.

Following is the code I use to do the bitmap loading and set it to the menu item.
code:
var Bitmaps = new Array(); //Global array storing the bitmaps by their path, so I can destroy them when they're no longer needed.

var hBitmap = LoadBitmap("Images\\logview.bmp"); //Load the bitmap
SetMenuItemBitmap(hMenu, i, hBitmap); //hMenu is a pop-up handle, i is the menu item position (in my case, it equals 1 to specify the 2nd item)

function LoadBitmap(sPath) {
    var IMAGE_BITMAP = 0;
    var LR_LOADFROMFILE = 0x10;
    var LR_LOADTRANSPARENT = 0x20;
    var sFilePath = PathAppend(MsgPlus.ScriptFilesPath, sPath); //PathAppend is a function to append two paths by calling PathAppendW in shlwapi.
    var hImage = Interop.Call('user32', 'LoadImageW', 0, sFilePath, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_LOADTRANSPARENT);
    if(hImage !== 0) Bitmaps[sPath] = hImage; //Adds the bitmap handle to the global array.
    return hImage;
}

function SetMenuItemBitmap(hMenu, uItem, hBitmap) {
    var MIIM_BITMAP = 0x80;
    var MENUITEMINFO = Interop.Allocate(48);
    with(MENUITEMINFO) {
        WriteDWORD(0, Size);
        WriteDWORD(4, MIIM_BITMAP);
        WriteDWORD(44, hBitmap);
    }
    Interop.Call("user32", "SetMenuItemInfoW", hMenu, uItem, 1, MENUITEMINFO);
}
Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
08-22-2007 10:42 AM
Profile E-Mail PM Web Find Quote Report
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On