Re: Redraw Transparent Window

Tech-Archive recommends: Fix windows errors by optimizing your registry



"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


.



Relevant Pages

  • Re: Is it possible to force a covered window to repaint itself ?
    ... One possibility would be to take a screenshot of the entire screen, ... this onto a fullscreen window that you have created. ... Everything is OK with the transparent window design, ... covered window beneath it can repaint itself, stylus events are ...
    (microsoft.public.pocketpc.developer)
  • Window transparency dilemma
    ... I'm seeing some strange PM behavior that I can't quite understand, apparently relating to whether or not a window was created in a given process. ... I've been able to re-capture the bitmap underneath the window by triggering off of when my window's visible region changes ... My logic here is that if the user changes the Z-order of a window underneath my transparent window, my transparent window's visible region will change. ... WinSetVisibleRegionNotify(myWin, TRUE); ...
    (comp.os.os2.programmer.misc)
  • Re: Window transparency dilemma
    ... After calling WinBeginEnumWindows, ... My transparent window has the desktop as ... pair of messages to my transparent window. ... window ULONG flag), beg the windows underneath to draw themselves, do ...
    (comp.os.os2.programmer.misc)
  • Re: Window transparency dilemma
    ... My transparent window has the desktop as its parent/owner. ... When a completely different window from within the same process, with the desktop also as its parent/owner loses the window focus by the user clicking on the desktop, I get a WM_VRNDISABLE/ENABLE pair of messages to my transparent window. ... When this happens, I hide my transparent window, beg the windows underneath to draw themselves, do the DosSleep, and then capture the bitmap where my window used to be and draw the transparent window again. ...
    (comp.os.os2.programmer.misc)
  • Re: Mouse-click "transparent" window
    ... Depending on what I return to the system upon this message, the system will either post the mouse message to my window or will do a WM_NCHITTEST with the next window underneath. ... HTTRANSPARENT, then the mouse message just expires. ... Probably your best bet is to forward the message to the underlying window ... the message so that it refers to the client coordinates of the underlying ...
    (microsoft.public.win32.programmer.ui)