Home

GetWindowDC

GetWindowDC is a Win32 API function that retrieves a handle to a device context (HDC) for an entire window, including the non-client areas such as the title bar, borders, scroll bars, and menus. It is part of the Windows GDI (Graphics Device Interface) and is used when drawing or examining the full visual extent of a window outside just its client area.

When a window's client area is drawn, applications typically use GetDC to obtain a device context for

The function takes a window handle (HWND) and returns an HDC on success or NULL on failure.

Best practices advise using GetWindowDC sparingly and avoiding it for normal painting tasks. For client-area painting,

See also: GetDC, GetDCEx, ReleaseDC, BeginPaint, EndPaint.

the
client
region.
GetWindowDC,
in
contrast,
provides
a
device
context
that
encompasses
both
client
and
non-client
regions
of
the
specified
window.
This
can
be
useful
for
tasks
that
involve
manipulating
or
inspecting
non-client
elements,
but
it
should
be
used
with
care
because
non-client
rendering
is
handled
by
the
system
in
many
contexts.
If
a
DC
is
obtained,
it
must
be
released
with
ReleaseDC
when
drawing
is
complete.
The
DC
obtained
by
GetWindowDC
is
not
intended
for
long-term
painting
and
may
require
additional
handling
when
the
window
is
being
redrawn
or
themed.
BeginPaint/EndPaint
within
a
WM_PAINT
handler
is
recommended.
For
non-client
customization,
alternative
APIs
or
mechanisms
provided
by
the
system
should
be
considered,
as
non-client
drawing
is
often
managed
by
the
window
manager.