Reputation:
When a part of the window needs to be repainted, the area is marked as invalid, and when I repaint the area (in the WM_PAINT
event handler), I should mark the area as valid.
But I don't understand what is the need for marking the area as invalid and then validating it later, I mean why not just do the following: when an area needs to be repainted, just send a WM_PAINT
message (without marking the area as invalid) and then just repaint the area (without marking it as valid).
Upvotes: 0
Views: 128
Reputation: 10489
Marking an area as INVALID
lets windows know that it is in need of updating. This is to allow partial paints of the screen instead of just completely updating the draw area every pass.
It's a good idea to only invalidate areas of change in mostly static programs to reduce draw overhead.
Validating them after the draw has completed lets windows know that the area has been refreshed and does not need to be redrawn again.
An example of where this would be useful is when you have the following type of window:
When scrolling through the list boxes or ticking the check boxes it is better to only invalidate that area of the window for redraw rather than redrawing the whole window every time the list box or check box needs to be updated to show the new scroll position or check mark.
Upvotes: 1
Reputation: 182779
Imagine someone's throwing balls at a fence. Do you repaint the fence as many times as balls hit it? No, you repaint the fence if, and only if, a ball hit it since the last time you repainted.
You're suggesting that any time an area would be marked invalid, instead a WM_PAINT
message should be sent to the application. The big problem with this is that if the same area got invalidated many times, that would result in many WM_PAINT
messages being sent and no way to know that many of them have already been handled. So at the time when you most need high performance (because you're falling behind on drawing) you'd have to repeat the same drawing operations over and over. That doesn't make sense.
Upvotes: 1