Important:
This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.
A version of this page is also available for
4/8/2010

Sent by an application when Windows or another application makes a request to paint a portion of an application's window.

Syntax

WM_PAINT 
hdc = (HDC) 
wParam;

Parameters

hdc

Handle to the device context (HDC) in which to draw.

If this parameter is NULL, use the default device context.

This parameter is used by some common controls to enable drawing in a device context other than the default device context.

Other windows can safely ignore this parameter.

Return Value

An application should return zero if it processes this message.

Remarks

An application sends the WM_PAINTmessage when the operating system or another application makes a request to paint a portion of the application's window. This message is sent when UpdateWindowis called, or it is sent by DispatchMessagewhen the application obtains a WM_PAINTmessage by calling GetMessageor PeekMessage. The sequence of events follows this order:

  • DispatchMessagedetermines where to send this message.

  • GetMessageor PeekMessagedetermines which message to dispatch, and returns this message when there are no other messages in the application's message queue.

  • DispatchMessagesends this message to the appropriate window procedure.

The system sends an internal WM_PAINTmessage only once. After the internal message is returned from GetMessageor PeekMessage, or is sent to a window by UpdateWindow, the system does not post or send any more WM_PAINTmessages until the window is invalidated.

An application must call BeginPaintand EndPaintin response to WM_PAINTmessages, or pass the message to the DefWindowProcfunction to validate the window. DefWindowProcvalidates the update region; it can send the WM_ERASEBKGNDmessage 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_PAINTmessage, because a WM_PAINTmessage may have been caused by a non-NULL update.

For some common controls, the default WM_PAINTmessage processing checks the wParamparameter. If wParamis non-NULL, the control assumes that the value is a handle to a device context (HDC) and paints using that device context.

Requirements

Header winuser.h
Windows Embedded CE Windows CE 1.0 and later
Windows Mobile Windows Mobile Version 5.0 and later

See Also