views:

2329

answers:

4

Hi All,

First, I'm working on Win32 with C++.

I have been trying to implement a transparent window with a child window which should remain 100% opaque. It seems that child controls cannot have opacity better (ah.. lower) than the parent and if I make my parent 100% transparent then my child control also inherits the transparency.

Code that I use -

SetLayeredWindowAttributes(GetParent(parentWindowHwnd), 0, 0, LWA_COLORKEY, LWA_ALPHA);

Any help?

Please also reply if I am not very clear with my question.

-Manoj

A: 

It's a Win32 FAQ for a long time (tranaparency exists before layered windows...)
See Google Groups, Win32
(samples in C)

+1  A: 

I'm certain you can do it the other way round, i.e. an opaque main window with a transparent child window, so the reverse may also be true. Have you tried unsetting the WS_EX_LAYERED flag for the child window and then redrawing it to make it completely opaque again?

// Remove WS_EX_LAYERED from the window styles
SetWindowLong(hChildWnd, 
              GWL_EXSTYLE,
              GetWindowLong(hChildWnd, GWL_EXSTYLE) & ~WS_EX_LAYERED);

RedrawWindow(hChildWnd, 
             NULL, 
             NULL, 
             RDW_ERASE | RDW_INVALIDATE | RDW_FRAME | RDW_ALLCHILDREN);

The MSDN page on Layered Windows may also help.

porkchop
Tried but this did not work.
Manoj Awasthi
+2  A: 

You can't do this unfortunately, child windows always have the same opacity as their parent. The Google Desktop Toolbar had a neat trick to give the illusion of an opaque textbox on a translucent background. They created two top level windows, one of the background and one for the textbox. Then they set the background window as the owner (not the parent) of the texbox. They then set the background as transparent. It's quite a bit of work to get right, but it's the only way to do it without rendering the whole thing yourself using UpdateLayeredWindow.

Mo Flanagan
Quick question: how to set the background window as the owner of the texbox?
Stefan
A: 

Hello,
You cannot make a child control less transparent than its parent. The usual approach here is to give your window an irregular shape: not a rectangle. This is much older that alpha transparency - Think about a clock application: you can make your window circular if you wanted, even on windows 95.
This could be done using the Windows API function SetWindowRgn:
A simple (vb) example - http://www.xs4all.nl/~rjg70/vbapi/ref/s/setwindowrgn.html
Google it - http://www.google.com/search?hl=en&q=windows+api+setwindowrgn

Kobi