Hi, for one of my windows i need "see through" back ground. I am not using layered windows (nor i like to ujse it), because i need to have the window enabled for user actions, but should look as if it is not there.
So I thought of getting periodic screeshots of the screenDC and using it to bitblt over my window before drawing on it. Like having a camera on your back and projectings its output on you get invisible effect.
For this logic I need screen contents below my window. So I used
But with this I am getting my window content only, so I am ending nowhere..
My whole function looks like below:
void MakeWindowTransparent(HDC PaintDC,HWND hwnd,HRGN hWndRgn)
{
/*adding some code to get the window back ground*/
HDC ScreenDC,ScreenShotDC;
int ScreenWidth,ScreenHeight;
HBITMAP ScreenShotBitmap;
int Width,Height,Top,Left;
This will be called in response to WM_PAINT before drawing anything else with the DC returned with BeginPaint.
Please suggest where i am missing...
drew_canitz
August 23rd, 2007, 09:45 AM
Have you tried CreateDC("DISPLAY",NULL,NULL,NULL)?
I tried to do something similar as my first attempt at non-square windows. It became difficult because I had to hide my window to get a screenshot of things below. I would then have to show my window. It wasn't a good user experience and never ended up working right.
WinAmp does window opacity, so I know it's possible. I don't know how to do it though. Maybe this article will give you some more clues...
http://www.codeproject.com/dialog/smoothalpha.asp
mvadu
August 23rd, 2007, 10:46 AM
Have you tried CreateDC("DISPLAY",NULL,NULL,NULL)?
I tried to do something similar as my first attempt at non-square windows. It became difficult because I had to hide my window to get a screenshot of things below. I would then have to show my window. It wasn't a good user experience and never ended up working right.
WinAmp does window opacity, so I know it's possible. I don't know how to do it though. Maybe this article will give you some more clues...
http://www.codeproject.com/dialog/smoothalpha.asp
The article you suggested uses LayeredWindows and SetLayeredWindowAttributes(). As I said earlier I don't want to use them.
Let me try CreateDC("DISPLAY",NULL,NULL,NULL) any way..
I tried hide window-- take snap-- show window, but it killed explorer as every time it hides it needs to update taskbar. Also when you show it again it basically triggers WM_PAINT going in to recursive loop :(.
JVene
August 23rd, 2007, 02:59 PM
While I think I know what you want, I'm not certain of what your use of the transparent window might be, but....
If you want to use the WX_EX_TRANSPARENT style and provide a region, you can create non-rectangular windows.
You can override the WM_ERASEBKGND message, and do nothing. This causes the window to remain invisible if you also don't paint anything, or if you do - paint only some portion of the display, creating the effect of a 'windowless graphic'. The effect may be incorporated with other window styles that avoid the frame, title bar, etc.
You might also need to consider 'forwarding' mouse messages (or related) to other windows, if that comes up in your design.
mvadu
August 24th, 2007, 01:23 AM
While I think I know what you want, I'm not certain of what your use of the transparent window might be, but....
You might also need to consider 'forwarding' mouse messages (or related) to other windows, if that comes up in your design.
Well.. I am doing some thing like a analog clock.. user must be able to see the clock and it should not distract him from usual work either.
So I need a transparent background.. I don't want to use Layered windows as, if I make a window completely transparent using layers every thing including the contents which i need to be on the screen will become transparent. Also i don't want to pass on mouse messages to underneath window as with layered transparent window. User should be able to move my window if he wishes without changing transparency settings.
Hope I am clear in my requirements..
mvadu
August 24th, 2007, 02:03 AM
If you want to use the WX_EX_TRANSPARENT style and provide a region, you can create non-rectangular windows.
I have not yet tried your suggesion, but a quick glance at msdn article http://support.microsoft.com/kb/92526 says
Moving the WS_EX_TRANSPARENT window, however, results in the old window background moving to the new position, because Windows does not support fully functional transparent windows.
WS_EX_TRANSPARENT was designed to be used in very modal situations and the lifetime of a window with this style must be very short.
I doubt if i can use it..
JVene
August 25th, 2007, 05:03 PM
If you read my post again, you'll notice I have two different suggestions.
The WS_EX_TRANSPARENT window was the first.
The second suggestion is to avoid the erase of the background, forming a window without a frame.
When you paint on that you can perform a wide range of effects, including the use of alphablending.
You can also consider alphablending by setting the 'alpha' of the window itself, depending on the OS versions you intend to support (2000 and up).
mvadu
August 28th, 2007, 05:42 AM
I tried that too.. I am getting a transparent background, but it will have a previous image of my window, so it paints over its previous stage, thus spiling the view.. i am finding it difficult to explain.. please refer the attached image..
mvadu
August 31st, 2007, 01:09 AM
I think I am done with my requirements...
My working solution is to create a pattern brush from the window background.. then use that to PatBlt in ERASEBKGND message..
Below is the working code..
HBRUSH GetTransBkGndBrush(HDC PaintDC,HWND hwnd,HRGN hWndRgn)
{
/*adding some code to get the window back ground*/
HDC ScreenDC,ScreenShotDC;
// int ScreenWidth,ScreenHeight;
HBITMAP ScreenShotBitmap;
int Width,Height,Top,Left;
LOGBRUSH brBackGround;
HBRUSH hNewBackGnd;
RECT CurrentPos;