welw Blog About me

InvalidateRect is how you mark that a window should be re-drawn

In the older days, back when Charles Petzold used to be very popular among Windows programmers, many developers knew about mysterious tricks that we don't need to use nowadays.

Every Windows program works like a message loop. When Windows loads a program to the memory, it runs in an infinite loop:

while (GetMessage()) {
    ParseMessage()
}

Each program once in a while receives a message. These messages may be user interactions (an user is clicking a button) or Windows wishes to re-paint a client window.

When client window receives WM_PAINT message, the client will handle the message and update it's client area.

What if a window was unable to handle its WM_PAINT message because of a bug in the application or the application hung, it would leave old client area as is, resulting in the back in the day famous effect:

folder.png

But what about InvalidateRect? What was it used for?

The answer is: Using InvalidateRect the programmer could choose which areas of the client window should be re-painted during the next WM_PAINT message.