I'd like to create a Direct2D application that has a transparent background on which a few opaque complex controls are placed. The problem can be broken into several sub-problems:
Architecture: Should the controls be implemented as child windows? I think that this is the correct approach, rather that creating Direct2D polygons that implement a child-window functionality.
I tried to implement this by initializing the parent window:
SetWindowLong(m_hwnd, GWL_EXSTYLE, GetWindowLong(m_hwnd, GWL_EXSTYLE) | WS_EX_LAYERED);
SetLayeredWindowAttributes(m_hwnd, 0, (255 * 50) / 100, LWA_ALPHA);
And create the child window as WS_CHILD. This resulted in a child on which all D2D drowings including background are transparent. I could not find a way to make the child opaque. When I create the child window as WS_POPUP or WS_OVERLAPPED the opacity problem is solved but the child window is located on the desktop unrelated to the parent.
Layered Window? I chose to work with Layered Windows but since I target at VistaSP2 and higher there might be better solutions. I tried the solution offered here but I too failed to implement it.
Do you mean to create a 32-bit-per-pixel window? (Sorry for being unable to comment, not enough rep over here)
In that case, you are FORCED to use UpdateLayeredWindow (and a CreateDIBSection call while you initialize), no matter what, every time you finished drawing the scene, after you finished drawing the scene, like:
About the initialization:
About the freeing of the resources:
EDIT: MemDC, OldBmp and DIBSectionBitmap are Per-Window. MemDC is a HDC. OldBmp is a HBITMAP. DIBSectionBitmap is a HBITMAP. At this point you can draw your child windows as if they were part of your very own main window, with a per-pixel alpha precision, but you'll need to handle focusing and messaging on your own.