OK, here's my collection of horrible hacks. The hWnd parameter is the window you have just resized. hPaintWnd is the window you are going to draw into. On XP, these can be the same (but not under Aero). gIsXP is false on Windows 2000 (where PrintWindow is not supported), true on XP and Vista. The rest you already know. GetRelativeWindowRect is the most useful helper function I ever wrote, by the way. Good luck!
#ifndef PW_CLIENTONLY
#define PW_CLIENTONLY 0x00000001
#endif
.
extern "C"
{
typedef WINUSERAPI BOOL (WINAPI * tPrintWindow) (HWND hwnd, HDC hdcBlt, UINT nFlags);
}
.
// GradientWindow::SmoothUpdate - repaint this window without flicker
void GradientWindow::SmoothUpdate (HWND hWnd, HWND hPaintWnd)
{
if (!IsWindowVisible (hWnd)) // but beware WM_SETREDRAW (TRUE)
return;
.
RECT wr;
wr.left = wr.top = 0;
if (hWnd != hPaintWnd)
GetRelativeWindowRect (hWnd, hPaintWnd, &wr);
hWnd = hPaintWnd;
.
RECT ur;
GetClientRect (hWnd, &ur);
ValidateRect (hWnd, &ur);
.
int width = ur.right;
int height = ur.bottom;
.
RECT r;
GetWindowRect (hWnd, &r);
POINT pt = { 0 };
ScreenToClient (hWnd, &pt);
int x_offset = -pt.x - r.left;
int y_offset = -pt.y - r.top;
width += x_offset;
height += y_offset;
.
for ( ; ; )
{
DWORD style = GetWindowLong (hPaintWnd, GWL_STYLE);
if ((style & WS_CHILD) == 0)
break;
HWND hParent = GetParent (hPaintWnd); // else Aero doesn't draw
if (hParent == NULL)
break;
hPaintWnd = hParent;
}
.
HDC hDC = GetDC (hPaintWnd);
assert (hDC);
wr.left = wr.top = 0;
if (hWnd != hPaintWnd)
GetRelativeWindowRect (hWnd, hPaintWnd, &wr);
.
HDC hMemDC = CreateCompatibleDC (hDC);
assert (hMemDC);
HBITMAP hBitmap = CreateCompatibleBitmap (hDC, width + wr.left, height + wr.top);
assert (hBitmap);
HBITMAP hOldBitmap = (HBITMAP) SelectObject (hMemDC, hBitmap);
.
// We prefer not to use WM_PRINT because:
// (a) it does not paint themed window borders correctly
// (b) URLControl's don't highlight the selected text
// (c) brush origin problems on Windows 2000 (but no gradients there anymore, so OK)
if (!gIsXP) // no PrintWindow () on Windows 2000
SendMessage (hWnd, WM_PRINT, (WPARAM) hMemDC,
PRF_ERASEBKGND | PR