Via the suggestion box, Martin Filteau asks
Could you explain the implementation of WM_PRINTCLIENT?
It seems that even MS got it wrong in the LISTBOX control.
Try to AnimateWindow a window that as a LISTBOX control as a child. The LISTBOX displays correctly if it is NOT empty. However, if it is empty… nothing is drawn.
I got a similar problem when embedding an Internet Explorer control.
Thanks.
-mf
As I noted back in 2003,
the implementation of WM_PRINTCLIENT
is the same as
that of WM_PAINT
.
In particular, the implementation of WM_PRINTCLIENT
for
an empty window is… to paint nothing.
That’s why the window is empty.
In other words, the listbox control is correct to draw nothing when it is empty. To draw the empty set, you draw nothing!
Let’s make some changes to the scratch program to show that animating a window with an empty listbox as a child works just fine.
BOOL OnCreate(HWND hwnd, LPCREATESTRUCT lpcs) { RECT rc; GetClientRect(hwnd, &rc); g_hwndChild = CreateWindow( TEXT(“listbox”), NULL, WS_CHILD | WS_VISIBLE | WS_TABSTOP, 0, 0, (rc.right – rc.left)/2, rc.bottom – rc.top, hwnd, (HMENU)1, g_hinst, 0);return TRUE; }
BOOL InitApp(void) { … wc.hbrBackground = (HBRUSH)(COLOR_APPWORKSPACE + 1); … }
int WINAPI WinMain(HINSTANCE hinst, HINSTANCE hinstPrev, LPSTR lpCmdLine, int nShowCmd) { … //
ShowWindow(hwnd, nShowCmd);AnimateWindow(hwnd, 2000, AW_VER_POSITIVE); … }
Just to emphasize that the white background in the listbox is really
being drawn by the listbox’s WM_ERASEBKGND
handler
and isn’t just leftover pixels from its parent window,
I’ve positioned the listbox so it covers only half of the parent
window and set the parent window’s
background to the application workspace color.
(If your application workspace color is the same as
the window color, then set the parent background color to something else.
I can’t believe I had to write that.)
With that simple set-up, we ask AnimateWindow
to show
our window, and specify a custom animation time so it’s easier to
see that the color is correct throughout the entire animation.
The listbox child window does appear correctly:
All you get is the window background.
Nothing is drawn. just like it’s supposed to be.
(This particular entry falls into another category of frustrating comment: The comment that claims that something doesn’t work when it does, and forces me to write a test program to prove it.)
0 comments