Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Q: ShowWindow() vs UpdateWindow()

511 views
Skip to first unread message

Richard Jordon

unread,
Apr 15, 1996, 3:00:00 AM4/15/96
to
I've just started working through Programming Windows 95 by Charles
Petzold and I'm afraid I'm already a bit at a loss in chapter 2. In
discussing the calls ShowWindow(), and then UpdateWindow, Petzold
writes "[UpdateWindow()]...then causes the client area to be painted.
It accomplishes this by sending the window proceedure a WM_PAINT message."

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


Raymond Chen

unread,
Apr 16, 1996, 3:00:00 AM4/16/96
to
ShowWindow(hwnd, SW_SHOW) means "make the window visible". As a
consequence of being visible, the system will give it WM_PAINT
messages when the system decides that the window needs to be painted.

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.

Mike Enright

unread,
Apr 18, 1996, 3:00:00 AM4/18/96
to
rjo...@interoz.com (Richard Jordon) wrote:
[snip]

>Does ShowWindow() generate a WM_PAINT? and, if it does, why call
>UpdateWindow() at all when initially displaying a window?

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

Alan Stokes

unread,
Apr 18, 1996, 3:00:00 AM4/18/96
to Richard Jordon
Richard Jordon wrote:
>
> I've just started working through Programming Windows 95 by Charles
> Petzold and I'm afraid I'm already a bit at a loss in chapter 2. In
> discussing the calls ShowWindow(), and then UpdateWindow, Petzold
> writes "[UpdateWindow()]...then causes the client area to be painted.
> It accomplishes this by sending the window proceedure a WM_PAINT message."
>
> 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?
ShowWindow causes a WM_PAINT message to be queued (as does anything which makes a
previously hidden part of a window visible). All that UpdateWindow does is to cause
any outstanding paint message to be delivered immediately, waiting until the paint
processing is complete until returning. Without the call to UpdateWindow the message
isn't received until the app goes into its message loop.

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

0 new messages