[comp.windows.ms.programmer] WM_PAINT - updating window?

oreillyj@ul.ie (12/13/90)

I'm just starting programming using the MS C Windows SDK and am having
a problem, the solution to which I cannot find in any of the manuals.
It has to do with the WM_PAINT message i.e. how do you, in general, update
the screen after obtaining this message (e.g. when the window size changes).
I originally thought that some form of screen backup and restoring would be
required but again I couldn't find anything to do this.  
	I apologize if this turns out to be a trivial task that is 
actually documented but I'd still appreciate any help.

John O'Reilly,
Email: oreillyj@ul.ie

spolsky-joel@cs.yale.edu (Joel Spolsky) (12/14/90)

In article <10801.276764aa@ul.ie> oreillyj@ul.ie writes:
>I'm just starting programming using the MS C Windows SDK and am having
>a problem, the solution to which I cannot find in any of the manuals.
>It has to do with the WM_PAINT message i.e. how do you, in general, update
>the screen after obtaining this message (e.g. when the window size changes).

Well, you just have to remember what you have on your screen and then
be able to recreate it on demand. This depends heavily on what you
have up there.

The reason windows doesn't automatically keep a bitmap of covered up
windows is because that would be a serious waste of memory. For
example, my terminal program is taking up 3/4 of a VGA screen - a
bitmap of this area would require about 192 K. But all it contains is
about 2K worth of text! So it is better to let the application redraw
it than make windows remember what was there.

Yeah, it's a bit of a nuisance. The way most windows programs wind up
is that WM_PAINT contains the code for repainting the entire screen,
and if a quick change has to be made to the screen (in response to
some user action, usually) that is done by getting a DC and painting.
In principle the WM_PAINT message also tells you exactly what
rectangle is being revealed that you need to repaint, but since its
usually possible to do a complete repaint in < 1 second (depending
again on the application) most programmers ignore this data and just
repaint everything (easier than figuring out what went in that exact
region).

Another note - if you have a lot of screen display code in your
WM_PAINT case and you discover that something has just happened which
radically changes the screen, you might want to just Invalidate your
entire window. That will cause a WM_PAINT to be sent to you, then you
only have to have window painting code in one place.

Hope this helps,

Joel Spolsky
spolsky@cs.yale.edu                                     Silence = Death