GetWindowLongA function (winuser.h)

Retrieves information about the specified window. The function also retrieves the 32-bit (DWORD) value at the specified offset into the extra window memory.

Note  If you are retrieving a pointer or a handle, this function has been superseded by the GetWindowLongPtr function. (Pointers and handles are 32 bits on 32-bit Windows and 64 bits on 64-bit Windows.) To write code that is compatible with both 32-bit and 64-bit versions of Windows, use GetWindowLongPtr.

 

Syntax

LONG GetWindowLongA(
  [in] HWND hWnd,
  [in] int  nIndex
);

Parameters

[in] hWnd

Type: HWND

A handle to the window and, indirectly, the class to which the window belongs.

[in] nIndex

Type: int

The zero-based offset to the value to be retrieved. Valid values are in the range zero through the number of bytes of extra window memory, minus four; for example, if you specified 12 or more bytes of extra memory, a value of 8 would be an index to the third 32-bit integer. To retrieve any other value, specify one of the following values.

Value Meaning
GWL_EXSTYLE
-20
Retrieves the extended window styles.
GWL_HINSTANCE
-6
Retrieves a handle to the application instance.
GWL_HWNDPARENT
-8
Retrieves a handle to the parent window, if any.
GWL_ID
-12
Retrieves the identifier of the window.
GWL_STYLE
-16
Retrieves the window styles.
GWL_USERDATA
-21
Retrieves the user data associated with the window. This data is intended for use by the application that created the window. Its value is initially zero.
GWL_WNDPROC
-4
Retrieves the address of the window procedure, or a handle representing the address of the window procedure. You must use the CallWindowProc function to call the window procedure.
 

The following values are also available when the hWnd parameter identifies a dialog box.

Value Meaning
DWL_DLGPROC
DWLP_MSGRESULT + sizeof(LRESULT)
Retrieves the address of the dialog box procedure, or a handle representing the address of the dialog box procedure. You must use the CallWindowProc function to call the dialog box procedure.
DWL_MSGRESULT
0
Retrieves the return value of a message processed in the dialog box procedure.
DWL_USER
DWLP_DLGPROC + sizeof(DLGPROC)
Retrieves extra information private to the application, such as handles or pointers.

Return value

Type: LONG

If the function succeeds, the return value is the requested value.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

If SetWindowLong has not been called previously, GetWindowLong returns zero for values in the extra window or class memory.

Remarks

Reserve extra window memory by specifying a nonzero value in the cbWndExtra member of the WNDCLASSEX structure used with the RegisterClassEx function.

Examples

For an example, see Creating, Enumerating, and Sizing Child Windows.

Note

The winuser.h header defines GetWindowLong as an alias which automatically selects the ANSI or Unicode version of this function based on the definition of the UNICODE preprocessor constant. Mixing usage of the encoding-neutral alias with code that not encoding-neutral can lead to mismatches that result in compilation or runtime errors. For more information, see Conventions for Function Prototypes.

Requirements

Requirement Value
Minimum supported client Windows 2000 Professional [desktop apps only]
Minimum supported server Windows 2000 Server [desktop apps only]
Target Platform Windows
Header winuser.h (include Windows.h)
Library User32.lib
DLL User32.dll
API set ext-ms-win-ntuser-windowclass-l1-1-0 (introduced in Windows 8)

See also

CallWindowProc

Conceptual

GetWindowLongPtr

Reference

RegisterClassEx

SetParent

SetWindowLong

WNDCLASS

Window Classes