title: BitBlt + UpdateLayeredWindow and CreateDIBSection in 16-bit desktop color depth
body: <p>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.</p>
  
  <p>setup of memory-DC:</p>
  
  <pre><code>HDC hdcMemory = CreateCompatibleDC(NULL);
  HBITMAP bmpMemory = CreateDIBSection(hdcMemory, (BITMAPINFO*)&amp;m_BitmapInfoHeader,
  DIB_RGB_COLORS, (void **)&amp;m_pDIBSectionBits, NULL, (DWORD)0);
  SelectObject(hdcMemory, bmpMemory);
  </code></pre>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p>It think it's because of the lack of alpha channel information.</p>
  
  <p>So I googled so much for a solution. I found out that in this situation I have to create the memory-DC with</p>
  
  <pre><code>HDC hdcMemory = CreateDC(TEXT("DISPLAY"),NULL,NULL,NULL);
  </code></pre>
  
  <p>instead of CreateCompatibleDC(NULL). Because the compatible DC would give me a 16-bit DC.</p>
  
  <p>Drawing is better with CreateDC. But the whole window is still click-throughable and transparency is drawn black in the layered window.</p>
  
  <p>So I think the problem is with BitBlt or the BitmapInfoHeader of CreateDIBSection.</p>
  
  <ol>
  <li><p>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?</p></li>
  <li><p>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.</p></li>
  </ol>
  
  <hr>
  
  <p>I got a little bit closer to the 16-bit desktop color depth problem.</p>
  
  <pre><code>HDC hdcMemory = CreateCompatibleDC(NULL);
  </code></pre>
  
  <p>The above seems to work. But the result my UpdateLayeredWindow function produces looks messy.</p>
  
  <p>So, this is because the black color is missing! Every pixel that was full black gets transparent. You can see through and click though. All other pixel lose their black part und only get click through.</p>
  
  <p>I made a test: I opened Windows Paint.exe, made a surface of the windows width and height and black as filled color.</p>
  
  <p>Then I put it under my layered window (with the missing black color), took the layered window as forgeround window again, and ta-da, my layered window looks normal in combination with the shining through Paint.exe black pixels.</p>
  
  <p>So I expiremented with BitBlt and it's raster-operation parameter again. But no luck.</p>
  
  <p>How can I blend the black color with BitBlt to my DC before drawing with UpdateLayeredWindow?</p>