May 24th, 2012, 09:00 AM
Child Window with a Transparent Background
Hello, I am new to Windows programming. I am currently attempting to port an application from Mac OS to Windows. The application is written in C. This is what I have done so far: I have installed Windows 8 CP and Visual Studio 11 beta on a laptop. I have found an example from msdn called: "Direct2D desktop app printing sample".
I have decided to make it the starting point of my new application. Just because I don't like C++ too much, I have translated most of the code in C (but still keeping the .cpp extension). It works. The first true modification is that I want to add a second window and it must have a transparent background. The Mac application I am porting has two windows, although the user is not aware of this fact. The main window is opaque and draws a very complex plot. The overlay window is on top of it and hilights the selection and draws other temporary effects. When the selection changes, there is no need to draw the plot again (it would be extremely time-consuming).
The Windows example I have found creates a main window and a child window. Drawing is perfomed into the latter with Direct2D. I have created 2 child windows. In both cases I set wcex.hbrBackground = nullptr;
I have tried to intercept the message WM_ERASEBKGND but it does not arrive to my childs. My starting example start drawing with:
If I omit the Clear instruction the background becomes black. If I use a transparent color the background is still black. I have created the second window with the style WS_TRANSPARENT.
d2dContext->Clear( D2D1::ColorF( D2D1::ColorF::White ) );
I have two questions, if anybody is so kind to help me.
1. Is my approach correct? Is it possible to update one of the child windows without forcing the sibling to redraw itself? Or do I need two top-level windows?
2. How can I get a transparent background? The example that I have found is quite complicated. It creates the D2D1 device, its bitmap and a lot of other objects. Maybe I should change one of the properties of one of those objects.... maybe not.
Tags for this Thread
Click Here to Expand Forum to Full Width
This is a Codeguru.com survey!