Windows is not the only source of WM_PAINT messages. You can also generate WM_PAINT messages for your windows by using the InvalidateRect or InvalidateRgn functions. These functions mark all or part of a client area as invalid (in need of redrawing). For example, the following function invalidates the entire client area:
InvalidateRect(hWnd, NULL, TRUE);
This example invalidates the entire client area for the window identified by the hWnd parameter. The NULL argument, used in place of a rectangle structure, specifies the entire client area. The TRUE argument causes the background to be erased.
When the client area is marked as invalid, Windows posts a WM_PAINT message. If other parts of the client area are marked as invalid, Windows does not post another WM_PAINT message. Instead, it adds the invalidated areas to the previous area, so that all areas are processed by the same WM_PAINT message.
If you change your mind about redrawing the client area, you can validate parts of it by using the ValidateRect and ValidateRgn functions. These functions remove any previous invalidation and will remove the WM_PAINT message if no other invalidated area remains.
If you do not want to wait for the WM_PAINT message to be retrieved from the application queue, you can force an immediate WM_PAINT message by using the UpdateWindow function. If there is any invalid part of the client area, UpdateWindow pulls the WM_PAINT message for the given window from the queue and sends it directly to the window function.