The windowing system generally tries to avoid redrawing anything unless necessary, e.g. because something has changed, or another window has moved across it. When this happens, it marks the region as invalid to say that it needs to be redrawn. Alternatively, a region/window can be manually invalidated to force a redraw.
When the application responds to the WM_PAINT
message, it will try to be as efficient as possible by only redrawing in the invalidated area. When it's finished, it marks it as valid to indicate that it's now up-to-date.
This selective redraw approach isn't as important today as it used to be. In the past, the drawing operations were much slower, so optimisation was absolutely essential.