Home

GetWindowLong

GetWindowLong is a Windows API function in the user32.dll that retrieves a value associated with a specified window. It returns a LONG value based on the window handle (HWND) and an index (nIndex), which identifies the type of data to retrieve. The data can include a pointer or handle stored with the window, such as the window procedure, the instance handle, or values stored in the window’s extra memory.

Common indices used with GetWindowLong include GWL_WNDPROC (window procedure pointer), GWL_HINSTANCE (instance handle), GWL_STYLE and GWL_EXSTYLE

64-bit considerations and modern usage: On 64-bit Windows, pointers and handles are 64 bits, so GetWindowLong

Both GetWindowLong and GetWindowLongPtr have ANSI and Unicode variants (GetWindowLongA/W and their GetWindowLongPtr counterparts). In 64-bit

(window
styles),
GWL_ID
(control
identifier),
and
GWL_USERDATA
(per-window
user
data).
These
constants
define
the
kinds
of
information
you
can
query
about
a
window.
may
not
be
sufficient
or
safe
for
retrieving
pointer-sized
data.
The
recommended
function
is
GetWindowLongPtr,
which
takes
indices
defined
with
the
GWLP_
prefix,
such
as
GWLP_WNDPROC,
GWLP_HINSTANCE,
GWLP_STYLE,
GWLP_EXSTYLE,
GWLP_ID,
and
GWLP_USERDATA.
For
compatibility,
GWL_*
constants
map
to
the
same
meanings,
but
GetWindowLongPtr/SetWindowLongPtr
should
be
used
for
pointer-sized
data
and
for
modifying
window
attributes
in
64-bit
code.
applications,
GetWindowLongPtr
and
SetWindowLongPtr
are
preferred
for
retrieving
or
setting
window
data.
Note
that
a
zero
return
value
may
indicate
either
actual
data
or
an
error;
use
GetLastError
to
distinguish.