Hello there!
I have an application with transparent background in client area which is drawn black because the window is not layered. In each of it's WM_PAINT messages I am doing a BitBlt to a memory-DC, after that I use the memory-DC with UpdateLayeredWindow to a layered canvas window.
setup of memory-DC:
HDC hdcMemory = CreateCompatibleDC(NULL);
HBITMAP bmpMemory = CreateDIBSection(hdcMemory, (BITMAPINFO*)&m_BitmapInfoHeader,
DIB_RGB_COLORS, (void **)&m_pDIBSectionBits, NULL, (DWORD)0);
SelectObject(hdcMemory, bmpMemory);
In WM_PAINT I use the BitBlt function to copy the apps client area DC information to the memory-DC. After that I'm doing a UpdateLayeredWindow with the memory-DC to a layered canvas windows DC (its a CWnd). So it's in realtime, and the result is: I have the normal application window and a layered window besides with an irregular shape and per pixel transparency.
Everything works fine in 32-bit desktop color depth! If I switch to 16-bit, the layered canvas window gets messed up. The drawing looks bad and the whole window is click-though able.
It think it's because of the lack of alpha channel information.
So I googled so much for a solution. I found out that in this situation I have to create the memory-DC with
HDC hdcMemory = CreateDC(TEXT("DISPLAY"),NULL,NULL,NULL);
instead of CreateCompatibleDC(NULL). Because the compatible DC would give me a 16-bit DC.
Drawing is better with CreateDC. But the whole window is still click-throughable and transparency is drawn black in the layered window.
So I think the problem is with BitBlt or the BitmapInfoHeader of CreateDIBSection.
I don't know if to use BitmapInfoHeader.biBitCount = 32 or BitmapInfoHeader.biBitCount = 16 bit. Think it's 32. And what about biCompression -> BI_RGB or BI_BITFIELDS?
How to add the alpha channel information to the memory-DC after BitBlt(..., SRCCOPY) the 16-bit DC to the memory-DC, so that it works with UpdateLayeredWindow? (maybe: pre-multiply the rgb channels with the alpha channel?) Dunno how to do.
Thank you! :)
Regards
Chris