Re: ImageList_Draw and icons with alpha channel
- From: "Michael Phillips, Jr." <mphillips53@xxxxxxxxxxxxxxx>
- Date: Wed, 26 Oct 2005 11:19:20 -0400
I tried my suggestion with your code and it works for me.
Here are the changes that I made to demonstrate my suggestion:
.... // other code
HRSRC hResource = ::FindResource(_Module.GetResourceInstance(),
MAKEINTRESOURCE(10), RT_ICON); // 32bpp
if(hResource) {
HGLOBAL hMem = ::LoadResource(_Module.GetResourceInstance(), hResource);
if(hMem) {
LPVOID pIconData = ::LockResource(hMem);
if(pIconData) {
HICON hIcon = ::CreateIconFromResourceEx((PBYTE) pIconData,
::SizeofResource(_Module.GetResourceInstance(), hResource), TRUE,
0x00030000, 0, 0, LR_DEFAULTCOLOR);
if(hIcon) {
largeImageList.AddIcon(hIcon);
ICONINFO iconInfo;
// break out the image masks
GetIconInfo(hIcon, &iconInfo);
m_h32bppXORMask = iconInfo.hbmColor;
m_h32bppANDMask = iconInfo.hbmMask;
}
}
}
}
.... // other code
// add the 32bpp Alpha Icon Bitmap Masks to a new imagelist and draw it to
the dialog
WTL::CImageList iml;
iml.Create(32, 32, ILC_COLOR32 | ILC_MASK, 2, 0);
iml.Add(m_h32bppXORMask);
iml.Add(m_h32bppANDMask);
DeleteObject(m_h32bppXORMask);
DeleteObject(m_h32bppANDMask);
iml.SetBkColor(GetSysColor(COLOR_3DFACE));
iml.Draw(ps.hdc, 0, 10, 90, ILD_NORMAL);
iml.Destroy();
// Draw the captioned text next to the rendered imagelist bitmaps
SetBkColor(hDC, GetSysColor(COLOR_HIGHLIGHT));
SetTextColor(hDC, GetSysColor(COLOR_HIGHLIGHTTEXT));
rc.left = 50;
rc.top = 190;
rc.right = 90;
rc.bottom = 20;
DrawText(ps.hdc, _T("Hello"), 5, &rc, DT_EDITCONTROL | DT_NOPREFIX |
DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS);
"Timo Kunze" <TKunze71216@xxxxxx> wrote in message
news:ujTuP0c2FHA.2816@xxxxxxxxxxxxxxxxxxxxxxx
>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!
.
- Follow-Ups:
- Re: ImageList_Draw and icons with alpha channel
- From: Timo Kunze
- Re: ImageList_Draw and icons with alpha channel
- References:
- ImageList_Draw and icons with alpha channel
- From: Timo Kunze
- Re: ImageList_Draw and icons with alpha channel
- From: Michael Phillips, Jr.
- Re: ImageList_Draw and icons with alpha channel
- From: Timo Kunze
- Re: ImageList_Draw and icons with alpha channel
- From: Michael Phillips, Jr.
- Re: ImageList_Draw and icons with alpha channel
- From: Timo Kunze
- ImageList_Draw and icons with alpha channel
- Prev by Date: Re: GetDIBits question
- Next by Date: GetPixel from DIB
- Previous by thread: Re: ImageList_Draw and icons with alpha channel
- Next by thread: Re: ImageList_Draw and icons with alpha channel
- Index(es):
Relevant Pages
|