Skip to main content

8-bit alpha channel support on JDic Trayicon service for windows

1 reply [Last post]
Joined: 2004-09-13

Recently, I put a png file as an image for the tray icon.

It turns out the image is not looked as good as I expected.

I found that it is because the native code of the tray icon is only support 1 bit of transparency, not 8-bit as in Png format.

I modified Tray.cpp file with some code snipplet show in below. I wonder if anyone can help me to check it in?

The code doesn't support windows 95 and windows nt 4.0, but later windows.

typedef struct tagBitmapheader {
DWORD dwMasks[256];
} Bitmapheader, *LPBITMAPHEADER;


HBITMAP create_BMP(HWND hW,int* imageData,int nSS, int nW, int nH)
Bitmapheader bmhHeader;
char *ptrImageData;
HBITMAP hbmpBitmap;
HBITMAP hBitmap;

int nNumChannels = 4;

if (!hW) {
hW = ::GetDesktopWindow();
hDC = ::GetDC(hW);
if (!hDC) {
return NULL;

memset(&bmhHeader, 0, sizeof(Bitmapheader));
bmhHeader.bmiHeader.bV5Size = sizeof(BITMAPV5HEADER);
bmhHeader.bmiHeader.bV5Width = nW;
bmhHeader.bmiHeader.bV5Height = -nH;
bmhHeader.bmiHeader.bV5Planes = 1;

bmhHeader.bmiHeader.bV5BitCount = 32;
bmhHeader.bmiHeader.bV5Compression = BI_BITFIELDS;
// The following mask specification specifies a supported 32 BPP
// alpha format for Windows XP.
bmhHeader.bmiHeader.bV5RedMask = 0x00FF0000;
bmhHeader.bmiHeader.bV5GreenMask = 0x0000FF00;
bmhHeader.bmiHeader.bV5BlueMask = 0x000000FF;
bmhHeader.bmiHeader.bV5AlphaMask = 0xFF000000;

hbmpBitmap = ::CreateDIBSection(hDC, (BITMAPINFO*)&(bmhHeader),
NULL, 0);
int *srcPtr = imageData;
char *dstPtr = ptrImageData;
if (!dstPtr) {
ReleaseDC(hW, hDC);
return NULL;
for (int nOutern = 0; nOutern < nH; nOutern++ ) {
for (int nInner = 0; nInner < nSS; nInner++ ) {
dstPtr[3] = (*srcPtr >> 0x18) & 0xFF;
dstPtr[2] = (*srcPtr >> 0x10) & 0xFF;
dstPtr[1] = (*srcPtr >> 0x08) & 0xFF;
dstPtr[0] = *srcPtr & 0xFF;

dstPtr += nNumChannels;

// convert it into DDB to make CustomCursor work on WIN95
hBitmap = CreateDIBitmap(hDC,
(void *)ptrImageData,

::ReleaseDC(hW, hDC);
return hBitmap;

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2005-05-29

Hi Henry,
Thank you very much for your contribution to JDIC!
- I've opened an issue350( to trace it.Could you please wrap the codes in a complete c file and upload it as a patch?
- Another issue is about license, you have to sign a JCA of JDIC to show that we are authorized to use your code:) .You can find the guide of JCA here: Abstract is as below:

Contributing code
As mentioned above, JDIC is open source — all of the source code is available, and if there's a feature you'd like to see or a bug you'd like to see fixed, you have the power to make that happen. See the sections on contributing patches for more information.

All contributers must complete the Joint Copyright Assignment form before contributions can be included in the project. Print, complete, sign and mail or fax the Joint Copyright Assignment form to:

Sun Microsystems, Inc.
4120 Network Circle USCA 12-105
Santa Clara, CA 95054 USA
Fax: +1 650 482 6542

Or, send a scanned version to