Home

BeginPaint

BeginPaint is a Windows API function used to prepare a window’s client area for painting in response to the WM_PAINT message. It validates the window’s update region and returns a device context (HDC) that should be used for drawing. A PAINTSTRUCT structure is filled by the function; the HDC in this structure is the drawing surface, and rcPaint describes the rectangle that needs repainting.

Typical usage occurs inside a window procedure when handling WM_PAINT. The pattern is to declare a PAINTSTRUCT,

Key points: BeginPaint should only be called in response to WM_PAINT. It both provides the device context

If painting is needed outside of WM_PAINT, or if a DC is required without validating the update

See also: EndPaint, WM_PAINT, PAINTSTRUCT, GetDC, ReleaseDC.

call
BeginPaint
with
the
window
handle,
perform
drawing
with
the
returned
HDC,
and
finally
call
EndPaint
to
finish
painting.
The
rcPaint
member
can
guide
rendering
to
the
region
that
requires
updates,
and
the
clipping
region
is
typically
set
to
the
update
region
to
optimize
drawing.
for
painting
and
informs
the
system
which
region
has
to
be
repainted.
EndPaint
must
be
called
to
release
the
device
context
and
to
validate
the
painted
area,
allowing
the
system
to
mark
the
update
region
as
complete.
region,
GetDC
and
ReleaseDC
can
be
used,
but
they
do
not
perform
the
same
update-region
validation
that
BeginPaint/EndPaint
provide.