WM_PAINT Message Visual Programming
Posted by admin | Posted in Theory Subjects, Visual Programming | Posted on 09-11-2009
0
Windows programs call the function UpdateWindow during initialization in WinMain shortly before entering the message loop. Windows takes this opportunity to send the window procedure its first WM_PAINT message. This message informs the window procedure that the client area must be painted. Thereafter, that window procedure should be ready at almost any time to process additional WM_PAINT messages and even to repaint the entire client area of the window if necessary. A window procedure receives a WM_PAINT message whenever one of the following events occurs:
- A previously hidden area of the window is brought into view when a user moves a window or uncovers a window.
- The user resizes the window (if the window class style has the CS_HREDRAW and CW_VREDRAW bits set).
- The program uses the ScrollWindow or ScrollDC function to scroll part of its client area.
- The program uses the InvalidateRect or InvalidateRgn function to explicitly generate a WM_PAINT message.
In some cases when part of the client area is temporarily written over, Windows attempts to save an area of the display and restore it later. This is not always successful. Windows may sometimes post a WM_PAINT message when:
- Windows removes a dialog box or message box that was overlaying part of the window.
- A menu is pulled down and then released.
- A tool tip is displayed.
In a few cases, Windows always saves the area of the display it overwrites and then restores it. This is the case whenever:
- The mouse cursor is moved across the client area.
- An icon is dragged across the client area.
Dealing with WM_PAINT message requires that you alter the way you think about how you write to the video display. Your program should be structured so that it accumulates all the information necessary to paint the client area but paints only “on demand”—when Windows sends the window procedure a WM_PAINT message. If your program needs to update its client area at some other time, it can force Windows to generate this WM_PAINT message. This may seem a roundabout method of displaying something on the screen, but the structure of your program will benefit from it.
