BeginPaint function
Applies to: desktop apps only
The BeginPaint function prepares the specified window for painting and fills a PAINTSTRUCT structure with information about the painting.
Syntax
HDC BeginPaint( __in HWND hwnd, __out LPPAINTSTRUCT lpPaint );
Parameters
- hwnd [in]
-
Handle to the window to be repainted.
- lpPaint [out]
-
Pointer to the PAINTSTRUCT structure that will receive painting information.
Return value
If the function succeeds, the return value is the handle to a display device context for the specified window.
If the function fails, the return value is NULL, indicating that no display device context is available.
Remarks
The BeginPaint function automatically sets the clipping region of the device context to exclude any area outside the update region. The update region is set by the InvalidateRect or InvalidateRgn function and by the system after sizing, moving, creating, scrolling, or any other operation that affects the client area. If the update region is marked for erasing, BeginPaint sends a WM_ERASEBKGND message to the window.
An application should not call BeginPaint except in response to a WM_PAINT message. Each call to BeginPaint must have a corresponding call to the EndPaint function.
If the caret is in the area to be painted, BeginPaint automatically hides the caret to prevent it from being erased.
If the window's class has a background brush, BeginPaint uses that brush to erase the background of the update region before returning.
Examples
For an example, see Drawing in the Client Area.
Requirements
|
Minimum supported client | Windows 2000 Professional |
|---|---|
|
Minimum supported server | Windows 2000 Server |
|
Header |
|
|
Library |
|
|
DLL |
|
See also
- Painting and Drawing Overview
- Painting and Drawing Functions
- EndPaint
- InvalidateRect
- InvalidateRgn
- PAINTSTRUCT
- ValidateRect
- ValidateRgn
Send comments about this topic to Microsoft
Build date: 3/7/2012
[tfl - 29 04 12] Hi - and thanks for your post. Community content is not the appropriate place for technical support queries. Instead, you should visit the MSDN Forums at http://forums.microsoft.com/MSDN, where such posts are welcomed and where you stand a much better chance of getting your query resolved. Sorry if that's not the answer you wanted to hear.
- 6/23/2010
- Snuff Daddy
- 4/29/2012
- Thomas Lee
Does EndPaint need to be called if BeginPaint returns NULL?According to the docs for BeginPaint, "if the caret is in the area to be painted, BeginPaint automatically hides the caret to prevent it from being erased."
According to the docs for EndPaint, "if the caret was hidden by BeginPaint, EndPaint restores the caret to the screen."
So I'd say that even without a DC, these two functions should be paired.
[tfl - 29 04 12] Hi - and thanks for your post. Community content is not the appropriate place for technical support queries. Instead, you should visit the MSDN Forums at http://forums.microsoft.com/MSDN, where such posts are welcomed and where you stand a much better chance of getting your query resolved. Sorry if that's not the answer you wanted to hear.
- 4/17/2012
- Jhail
- 4/29/2012
- Thomas Lee