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 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!


.



Relevant Pages

  • Re: should i installed SP 2 in my PC?
    ... > suggestion or advice to help me out. ... using Windows XP "prettifications". ... You should at least turn on the built in firewall. ... My suggestion - upgrade. ...
    (microsoft.public.windowsupdate)
  • RE: Right click on "Properties" on removable media = Complete hang
    ... Suggestion One: ... Description of the Windows 2000 System File Checker ... drivers or programs that are installed in your computer. ... The system is running fine and there are no hardware problems nor hardware ...
    (microsoft.public.windows.server.migration)
  • Re: Internet Explorer Registry setings
    ... I will assume a "Windows" operating system is ... You should at least turn on the built in firewall. ... My suggestion - upgrade. ... This is spyware. ...
    (microsoft.public.security)
  • Re: Updating.
    ... Cumalative Security Update for Internet Explorer 7 for Windows XP ... When it lists what it finds - install the critical ones. ... Sometimes they have to proceed to method two from the first suggestion. ...
    (microsoft.public.windowsxp.security_admin)
  • RE: Internet timeouts on workstations
    ... The client systems in question are all brand new installs of Windows XP ... > Suggestion - Clean Settings in Internet Explorer: ... On the SBS Server and one of the problematic client ... Ethernet adapter Server Local Area Connection: ...
    (microsoft.public.windows.server.sbs)