I took this to mean that the code under the WM_PAINT case in the
wndproc wouldn't be executed until the UpdateWindow() function is
called. Unfortunately, when I take the UpdateWindow() call out and
rebuild the program the text "Hello Windows 95!" (which is drawn
under WM_PAINT case) still shows up immediately in the window.
Does ShowWindow() generate a WM_PAINT? and, if it does, why call
UpdateWindow() at all when initially displaying a window?
Thanks in advance
Richard Jordon
UpdateWindow() means "if the window is visible, send it a WM_PAINT
immediately".
The two aren't directly related, aside from the incidental fact that
they both happen to have something to do with painting.
When you call ShowWindow(SW_NORMAL) on a window that isn't showing,
the client area is effectively invalidated. At some later time while
your message loop runs, GetMessage or PeekMessage will notice that
there is nothing pending for the window except WM_PAINT, and then the
message that's filled in will be a WM_PAINT.
UpdateWindow refers to the same information that GetMessage uses, and
IF SOME PART OF THE WINDOW IS INVALID, your WindowProc will be called
with WM_PAINT as the message id. In other words, using UpdateWindow
insures that the WM_PAINT handler is invoked sooner rather than later.
So, a sequence like
WinMain(mumble)
{
HWND h;
h = CreateWindow(mumble);
ShowWindow(h, mumble);
UpdateWindow(h);
MassiveInitializeationFunctionThatTakesTenSeconds();
while (GetMessage())
{
TranslateMessage()
DispatchMessage()
//etc.
}
}
... invokes the WM_PAINT handler much sooner. The result is, in most
cases, more satisfying to the user. Without UpdateWindow, the window
would not be visible until the GetMessage() call finally found that
the only thing left to do was to return a WM_PAINT message.
It sounds like your test program just had very little to do between
when ShowWindow was called and when GetMessage was called. So, you
didn't notice the difference with or without UpdateWindow.
HTH
--------------
Mike Enright
75032...@compuserve.com
You can't see the difference because it happens too fast. I think it's still
sensible to use UpdateWindow, to ensure your app appears on screen as early as
possible.
--
Alan Stokes (al...@rcp.co.uk)
RCP Consultants Ltd
Didcot, UK