Home

GetDC

GetDC is a function in the Windows API that retrieves a handle to a device context (HDC) for drawing with the Graphics Device Interface (GDI). It is declared in Wingdi.h and implemented in Gdi32.dll.

If a window handle is provided (hWnd is non-NULL), GetDC returns a DC for the client area

The caller is responsible for releasing the device context by calling ReleaseDC with the same window handle

GetDC is suitable for immediate drawing outside of WM_PAINT, but its DC is not suitable for persistent

of
that
window.
If
hWnd
is
NULL,
GetDC
returns
a
DC
for
the
entire
screen.
The
returned
HDC
can
be
used
with
GDI
drawing
functions
to
render
graphics,
text,
or
other
visuals.
and
the
HDC
returned
by
GetDC.
Failure
to
release
the
DC
can
exhaust
system
resources.
In
WM_PAINT
processing,
BeginPaint
and
EndPaint
are
typically
preferred
over
GetDC
for
painting
the
client
area,
because
they
validate
the
update
region
and
integrate
with
the
system's
paint
cycle.
off-screen
rendering.
For
off-screen
or
memory
rendering,
developers
commonly
create
a
memory
DC
with
CreateCompatibleDC,
select
into
it,
and
then
Blit
the
result
to
a
window
DC
when
ready.
Related
functions
include
GetWindowDC
(which
retrieves
a
DC
for
the
entire
window,
including
non-client
areas)
and
GetDCEx
(which
allows
additional
clipping
and
flags),
as
well
as
ReleaseDC
and
CreateCompatibleDC.