Re: ImageList_Draw and icons with alpha channel

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



I still have problems to use the code in my app. Here is the simplified
code:

HDC hCompatibleDC = ::GetDC(NULL);
HDC hMemoryDC = ::CreateCompatibleDC(hCompatibleDC);
HBITMAP hDragImage = ::CreateCompatibleBitmap(hCompatibleDC, 100, 50);
HBITMAP hPreviousBitmap = (HBITMAP) ::SelectObject(hMemoryDC, hDragImage);
RECT rc = {0};
rc.right = 100;
rc.bottom = 50;
::FillRect(hMemoryDC, &rc, (HBRUSH) ::GetStockObject(WHITE_BRUSH));
::SetBkColor(hMemoryDC, ::GetSysColor(COLOR_HIGHLIGHT));
::SetTextColor(hMemoryDC, ::GetSysColor(COLOR_HIGHLIGHTTEXT));
HFONT hPreviousFont = (HFONT) ::SelectObject(hMemoryDC, hFont);

HDC hMaskMemoryDC = ::CreateCompatibleDC(hCompatibleDC);
HBITMAP hDragImageMask = ::CreateBitmap(100, 50, 1, 1, NULL);
HBITMAP hPreviousBitmapMask = (HBITMAP) ::SelectObject(hMaskMemoryDC,
hDragImageMask);
::FillRect(hMaskMemoryDC, &rc, (HBRUSH) ::GetStockObject(WHITE_BRUSH));

::ImageList_Draw(hSourceImageList, 8, hMemoryDC, 1, 1, ILD_NORMAL);
::ImageList_Draw(hSourceImageList, 8, hMaskMemoryDC, 1, 1, ILD_MASK);
rc.left = 50;
rc.top = 10;
rc.right = 100;
rc.bottom = 30;
::FillRect(hMemoryDC, &rc, ::GetSysColorBrush(COLOR_HIGHLIGHT));
::FillRect(hMaskMemoryDC, &rc, (HBRUSH) ::GetStockObject(BLACK_BRUSH));
::DrawText(hMemoryDC, _T("Hello"), 5, &rc, DT_SINGLELINE | DT_VCENTER |
DT_END_ELLIPSIS);

::SelectObject(hMemoryDC, hPreviousBitmap);
::SelectObject(hMaskMemoryDC, hPreviousBitmapMask);
::SelectObject(hMemoryDC, hPreviousFont);

HIMAGELIST hDragImageList = ::ImageList_Create(100, 50, ILC_COLORDDB |
ILC_MASK, 1, 0);
::ImageList_Add(hDragImageList, hDragImage, hDragImageMask);

::DeleteObject(hDragImage);
::DeleteObject(hDragImageMask);
::DeleteDC(hMemoryDC);
::DeleteDC(hMaskMemoryDC);
::ReleaseDC(NULL, hCompatibleDC);
return (LRESULT) hDragImageList;

hDragImageList will be used with ::ImageList_BeginDrag to visualize a
drag'n'drop operation.

The problems I have are:
1) On Windows XP, pixels with alpha transparency are not transparent.
Instead they're drawn in the color that I fill hMemoryDC with in the
beginning. On Windows 2003, alpha transparency is wrong if the drag
image is drawn with ImageList_Draw, but it is correct during drag'n'drop
(obviously ImageList_BeginDrag does some magic).
2) On Windows 2003, the text's background is a translucent white instead
of blue. The text itself is in solid white as expected. I've already
checked the system colors, but they are the same as on my Windows XP
system on which the text's background has the correct color.
3) If I use ILC_COLOR32 instead of ILC_COLORDDB, alpha transparency is
correct, but the text is completely missing.

Does anyone see what I'm doing wrong? I don't.
Timo
--
www.TimoSoft-Software.de - the home of ExplorerTreeView
Stop software patents!
.