I could begin by asking the question outright or by citing my sources (this, this, this, and this) descriptively, but I'll walk you ll through what I'm trying to do instead.
Let's start with a main window. It has its own window class whose hbrBackground
is set to COLOR_BTNFACE + 1
. Now let's do
EnableThemeDialogTexture(hwnd, ETDT_ENABLE | ETDT_USETABTEXTURE)
so the tab control we're about to add will be drawn with visual styles. (Try Windows XP with the standard Luna theme for best results.) Now let's add a tab control and two tabs.
On the first tab, we create an instance (let's call it container
) of a new window class. This window class is going to hold various controls. I could set hbrBackground
to COLOR_BTNFACE + 1
, but then it will draw over the tab background. So I want this new child window to be transparent. So what I do is
- set the class
hbrBackground
toGetStockObject(HOLLOW_BRUSH)
- set
container
's extended style toWS_EX_TRANSPARENT
- set the class
WM_ERASEBKGND
handler to doSetBkMode((HDC) wParam, TRANSPARENT); return 0;
to set the device context and have Windows draw the transparent background.
So far so good, right? I'm not sure if I'm really doing all this correctly, and I'd like this to also be flicker-free, which doesn't seem to happen: when I resize the window (at least in wine) I get either flicker or garbage drawn (even in child controls, somehow!). Windows XP in a VM just shows flicker. I tried tweaking some settings but to no avail.
But wait, now I want to have another control, one that just draws some bitmap data. On the next tab, create another container
, then have a third window class area
as a child of that. area
only draws in the upper-left 100x100 area and has scrollbars; the rest of the window area should be transparent.
Right now, what I have for area
is:
- the window class
hbrBackground
set toNULL
and stylesCS_HREDRAW
andCS_VREDRAW
set - the extended window style being
0
- the
WM_ERASEBKGND
simply doingreturn 1;
- the
WM_PAINT
filling the entire update rect withCOLOR_BTNFACE + 1
before drawing, and rendering all of it
This is flicker-free, but obviously not transparent. NOW I'm really not sure what to do, because I want the area
to be transparent in such a way that it shows the tab control background. Again, I tried tweaking settings to bring them closer to what I tried above with container
, but I got either flicker or invalidation leftovers when I tried.
So how do I get both of these custom control types (the container and the drawing area) to be both flicker-free and transparent?
I presently must target Windows XP at a minimum, though if the solution would be easier with Vista+ only I'd be happy to keep that solution on the side in case I ever drop XP support (unfortunately Stack Overflow doesn't let me hand out silver medals...).
Thanks!