Home

ReleaseDC

ReleaseDC is a Windows API function that releases a device context (DC) previously obtained with GetDC or GetWindowDC. It is used to return the DC to the system when drawing to a window or the screen is finished, so that GDI resources can be reused.

The function prototype is int ReleaseDC(HWND hWnd, HDC hDC). The hWnd parameter should be the window associated

The return value indicates success or failure: a nonzero value indicates success, while zero indicates failure.

Important caveat: DCs obtained through BeginPaint during WM_PAINT processing should not be released with ReleaseDC; they

Related functions include GetDC, GetWindowDC, EndPaint, and BeginPaint. In typical usage, code obtains a DC for

with
the
DC
being
released.
If
the
DC
was
obtained
for
the
entire
screen
using
GetDC(NULL),
you
should
pass
NULL
for
hWnd.
After
calling
ReleaseDC,
the
DC
handle
is
no
longer
valid
for
use.
In
case
of
failure,
diagnostic
information
may
be
obtained
via
GetLastError.
It
is
important
to
pair
each
successful
GetDC
or
GetWindowDC
with
a
corresponding
ReleaseDC
to
avoid
leaking
GDI
resources.
must
be
released
with
EndPaint.
ReleaseDC
is
intended
for
DCs
obtained
outside
the
paint
cycle.
drawing,
performs
rendering,
and
then
releases
the
DC
with
ReleaseDC,
for
example:
HDC
hdc
=
GetDC(hwnd);
/*
drawing
operations
*/
ReleaseDC(hwnd,
hdc);