BeginPaint (Windows CE 5.0)

Windows CE 5.0
Send Feedback

This function prepares the specified window for painting and fills a PAINTSTRUCT structure with information about the painting.

HDC BeginPaint( 
  HWND hwnd, 


Handle to the window to be repainted.
Long pointer to the PAINTSTRUCT structure that will receive painting information.

Return Values

The handle to a display device context for the specified window indicates success.

NULL indicates that no display device context is available.

To get extended error information, call GetLastError.

Code Example

The following code example shows a window procedure that processes a WM_PAINT message by using BeginPaint to prepare a window for painting, and then draws an icon or bitmap in the window.

Note   To make the following code example easier to read, error checking is not included. Do not use this code example in a release configuration unless you have modified it to include secure error handling.
#include <windows.h>

HICON ghIcon = NULL;
HBITMAP ghbmMask = NULL;
HBITMAP ghbmColor = NULL;

        HWND hWnd,                // window handle
        UINT message,             // type of message
        WPARAM wParam,            // additional information
        LPARAM lParam)            // additional information
    switch (message) {

        case WM_PAINT:
            PAINTSTRUCT ps;
            HDC hdc;
            COLORREF crTxt, crBk;

            hdc = BeginPaint(hWnd, &ps);

            if (ghIcon)
                DrawIcon(hdc, 10, 10, ghIcon);

            if (ghbmMask)
                DrawBitmap(hdc, 10, 50, ghbmMask);

            if (ghbmColor)
                DrawBitmap(hdc, 50, 10, ghbmColor);
            EndPaint(hWnd, &ps);

// Include case statements for other messages here.

        default:  // Pass the message on if unproccessed.
            return (DefWindowProc(hWnd, message, wParam, lParam));
    return (0L);


The BeginPaint function sets the clipping region of the device context to exclude any area outside the update region.

The update region is set by the InvalidateRect 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 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.


OS Versions: Windows CE 1.0 and later.
Header: Winuser.h.
Link Library: Coredll.lib, Winmgr.lib.

See Also

EndPaint | InvalidateRect | ValidateRect | WM_ERASEBKGND | WM_PAINT | PAINTSTRUCT

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.