1

I have a written a class which is able to display animated GIF files with Direct 2d as in this example from MSDN:

https://code.msdn.microsoft.com/windowsapps/Windows-Imaging-Component-65abbc6a/sourcecode?fileId=127204&pathId=969071766

The GIF which I display is a continuously growing/shrinking not filled blue circle. All other pixels are White / the Background is White.

Unlike the example posted I create a CWnd, without Caption and Border, with the size of the GIF, with a ID2D1RenderTarget filling the whole CWnd and place it above the Content of my MainFrame.

Since I never used Direct2d before I assumed I can simply apply SetLayerdWindow() on my CWnd to reach my goal of only displaying the blue Circle.

SetLayeredWindowAttributes(RGB(255,255,255), 204, LWA_ALPHA | LWA_COLORKEY);

This should result in a CWnd with no White Pixels + 80% Transparency. Unfortunately the resulting Window is 80% transparent but none of the WhitePixels where removed/ the white pixels are still drawn.

Why does LWA_COLORKEY not work in this case? And how can I achieve that either my CWnd or ID2D1HwndRenderTarget will draw white as fully transparent?!

Note:
Besides that I've tried just for fun to draw a fully transparent background with the ID2D1HwndRenderTarget like:

m_pHwndRT->Clear(D2D1::ColorF(D2D1::ColorF::White, 0.0f));

With Microsoft stating: "The alpha value for the color to be constructed. An alpha channel value ranges from 0.0 to 1.0, where 0.0 represents a fully transparent color and 1.0 represents a fully opaque color. The default value is 1.0."

Which results in a fully white opaque window... Which made me wonder if this whole Transparency stuff is working at all

Jan Raufelder
  • 287
  • 7
  • 23
  • 1
    Don't let the system allocate a redirection bitmap for your window. Have it use the Direct2D surface (and flip chain) only. Here's how: [Windows with C++ : High-Performance Window Layering Using the Windows Composition Engine](https://msdn.microsoft.com/magazine/dn745861.aspx). – IInspectable Aug 01 '16 at 15:39
  • When creating your render target don't forget to set premultiplied format. http://stackoverflow.com/a/10627669/99953 – vt. Aug 10 '16 at 21:09

0 Answers0