Re: Redraw Transparent Window
- From: "John Carson" <jcarson_n_o_sp_am_@xxxxxxxxxxxxxxx>
- Date: Sat, 23 Sep 2006 18:12:47 +1000
"DHarray" <info@xxxxxxxxxxxxxxxx> wrote in message
news:OXcWfkm3GHA.3428@xxxxxxxxxxxxxxxxxxxx
Hello
I'm looking after an other solution for redrawing a transparent
window.
I listed the main points and styles of my transparent window here:
/////////////////////////////////////////////////////////////////////////
// Register Window Class
WNDCLASSW wc = {0};
wc.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
wc.hbrBackground = NULL;
// ...
RegisterClassW(&wc);
// Create Window
CreateWindowExW(
WS_EX_TRANSPARENT,
g_WndClass,
NULL,
WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS,
0, 0, 0, 0,
m_hWndParent,
NULL,
g_hInst,
this);
/////////////////////////////////////////////////////////////////////////
OnPaint:
// Begin Paint
BeginPaint(m_hWnd, &ps);
GetClientRect(m_hWnd, &rc);
// Set Transparent Background
SetBkMode(ps.hdc, TRANSPARENT);
// Draw Text
TextOut(ps.hdc, ...);
EndPaint(m_hWnd, &ps);
/////////////////////////////////////////////////////////////////////////
The old solution was:
ShowWindow(hWnd, SW_HIDE);
ShowWindow(hWnd, SW_SHOW);
.. but that flickers the window, because it's called every second in
my app. So I tried InvalidRect() and then UpdateWindow() but when
drawing new text the new text is drawn over the old.
Any Ideas?
To prevent the appearance of new text being drawn over old, you need to
erase the old. If you have a transparent window, then there are basically
only two ways for that to happen:
1. Use an OPAQUE background for your TextOut call.
2. Have the window underneath the transparent window redraw itself.
I take it that you don't want the effect produced by 1., which leaves 2. as
your only option.
To reduce flickering, you should only get the underlying window to redraw
the section of the window where the text has changed.
Calling InvalidateRect should work, but apparently isn't working in your
case. Make sure you
1. Call it on the underlying window (the window with handle m_hWndParent
presumably),
2. If you have the WS_CLIPCHILDREN style on the underlying window, then also
call InvalidateRect on the transparent window.
If there is still too much flickering for your taste, you will need to
BitBlt from a memory device context (i.e., get the underlying window to draw
into the memory device context or get the contents of the underlying window
into the memory device context by some other means --- e.g., copying a
bitmap --- then write the text into the memory DC, then BitBlt from the
memory DC to the screen).
--
John Carson
.
- References:
- Redraw Transparent Window
- From: DHarray
- Redraw Transparent Window
- Prev by Date: Redraw Transparent Window
- Next by Date: Re: Redraw Transparent Window
- Previous by thread: Redraw Transparent Window
- Next by thread: Re: Redraw Transparent Window
- Index(es):
Relevant Pages
|