Sent by an application when Windows or another application makes a request to paint a portion of an application's window.
WM_PAINT hdc = (HDC) wParam;
An application sends the WM_PAINT message when the operating system or another application makes a request to paint a portion of the application's window. This message is sent when UpdateWindow is called, or it is sent by DispatchMessage when the application obtains a WM_PAINT message by calling GetMessage or PeekMessage. The sequence of events follows this order:
DispatchMessage determines where to send this message.
GetMessage or PeekMessage determines which message to dispatch, and returns this message when there are no other messages in the application's message queue.
DispatchMessage sends this message to the appropriate window procedure.
The system sends an internal WM_PAINT message only once. After the internal message is returned from GetMessage or PeekMessage, or is sent to a window by UpdateWindow, the system does not post or send any more WM_PAINT messages until the window is invalidated.
An application must call BeginPaint and EndPaint in response to WM_PAINT messages, or pass the message to the DefWindowProc function to validate the window. DefWindowProc validates the update region; it can send the WM_ERASEBKGND message if the window background needs to be erased.
In addition, an application must check for necessary internal painting by looking at its internal data structures for each WM_PAINT message, because a WM_PAINT message may have been caused by a non-NULL update.
For some common controls, the default WM_PAINT message processing checks the wParam parameter. If wParam is non-NULL, the control assumes that the value is a handle to a device context (HDC) and paints using that device context.