There is an extended window style known as
WS_. Explaining what this style does is kind of difficult, but it’s been on the list of future topics since 2003. Better late than never, I guess.
First of all, there are two unrelated senses of transparent in play. One is visual transparency: Pixels beneath the window can show through. The other is hit-test transparency: Do clicks on this window go to the window, or do they pass through to the window beneath?
And each of those senses of transparent is itself complicated.
Let’s look a hit-test transparency first. We saw some time ago that It’s Complicated. Different hit-testing functions use different methods of determining whether a click should be given to a window or pass through it. And the
WS_ extended window style plays into some of those rules. I’ll let you read the linked article to learn the details.
Okay, now to visual transparency. The
WS_ extended window style alters the painting algorithm as follows: If a
WS_ window needs to be painted, and it has any non-
WS_ windows siblings (which belong to the same process) which also need to be painted, then the window manager will paint the non-
WS_ windows first.
That “lets the other windows paint first” behavior is what gave the style its name, because if you let the other windows paint first, and then you paint on top of it, then the parts you don’t actually paint will appear to be transparent because the other windows’ pixels will show through.
Calling this painting style transparent is kind of overselling the feature. It’s really a very specific behavior which makes transparent rendering sort of possible; it’s not a just turn this on and you get transparent rendering feature.
It’s like taking a lump of coal and labeling it diamond. Or like those advertisements which say things like “Can create up to five million cups of coffee per day!”
In order to turn the flour into a cake, the window with the
WS_ window style needs to know not to draw opaquely. Because if it draws opaquely, then all the work the window manager did to get the other window to draw first (so you can draw on top of it) is for naught.
And sometimes the
WS_ window style doesn’t even work. For example, observe that if the windows are not siblings of each other, then the style has no effect. If the windows belong to different processes, then the style has no effect. If both windows are not invalid simultaneously, then the style has no effect. (I don’t know how you could get into that last state, but maybe you’re more creative than I am.)
Go ahead and use the
WS_ window style if that’s what you want. Just understand that it doesn’t get you what the name might promise. (Depending on your situation, a layered window may work better.)