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". http://code.msdn.microsoft.com/windo...-From-be62d249
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.
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.
Hi, welcome! I'm actually having a similar problem and was just about to post! I've been trying to create a new form from my main form to highlight an area of the main form, and would need it to be semi-transparent to show the user where to look but without hiding what I'm trying to show. The problem is, no mather how I set the new form's properties, it will not show semi-transparent!!
Not sure if this will help you, but this is what I have so far:
1. What I'm doing (and it's not working) is, on the child form, set:
.AllowTransparency = true;
.Opacity = 0.5 // 50%
.BackColor = Color.Blue;
.TransparencyKey = Color.Blue; // Same as BackColor
That should show a translucent window, but it doesn't work for me.
Not, I have not found a complete solution yet. Just because this is a performance issue, I have decided to redraw everything. The final effect is the same, but the program can become very slow is some cases. An alternative would be to save the static part of the drawing as a bitmap, instead of repeating it every time. That optimization would be equivalent to what I was expecting from the operating system. In this moment I have already turned my attention to other details of my program. I will return to the optimization much later on.