GetWindowLongPtr Function

The GetWindowLongPtr function retrieves information about the specified window. The function also retrieves the value at a specified offset into the extra window memory.

If you are retrieving a pointer or a handle, this function supersedes the GetWindowLong function. (Pointers and handles are 32 bits on 32-bit Microsoft 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_PTR GetWindowLongPtr(      
    HWND hWnd,     int nIndex );

Parameters

hWnd
[in] 

Handle to the window and, indirectly, the class to which the window belongs.

If you are retrieving a pointer or a handle, this function supersedes the GetWindowLong 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.

nIndex
[in] Specifies 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 the size of an integer. To retrieve any other value, specify one of the following values.
GWL_EXSTYLE
Retrieves the extended window styles. For more information, see CreateWindowEx.
GWL_STYLE
Retrieves the window styles.
GWLP_WNDPROC
Retrieves the pointer to the window procedure, or a handle representing the pointer to the window procedure. You must use the CallWindowProc function to call the window procedure.
GWLP_HINSTANCE
Retrieves a handle to the application instance.
GWLP_HWNDPARENT
Retrieves a handle to the parent window, if there is one.
GWLP_ID
Retrieves the identifier of the window.
GWLP_USERDATA
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.
The following values are also available when the hWnd parameter identifies a dialog box.
DWLP_DLGPROC
Retrieves the pointer to the dialog box procedure, or a handle representing the pointer to the dialog box procedure. You must use the CallWindowProc function to call the dialog box procedure.
DWLP_MSGRESULT
Retrieves the return value of a message processed in the dialog box procedure.
DWLP_USER
Retrieves extra information private to the application, such as handles or pointers.

Return Value

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 or SetWindowLongPtr has not been called previously, GetWindowLongPtr 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.

Function Information

Minimum DLL Versionuser32.dll
HeaderDeclared in Winuser.h, include Windows.h
Import libraryUser32.lib
Minimum operating systems Windows 95, Windows NT 3.1
UnicodeImplemented as ANSI and Unicode versions.

See Also

Tags :


Community Content

Stanley Roark
32-bit support?

This function is not exported in my 32 bit version of Windows Vista (Home premium) (also looked on older Windows XP (Home edition) system).

So how can this documentation say "To write code that is compatible with both 32-bit and 64-bit versions of Windows, use GetWindowLongPtr." when you cannot import this function on a 32 bit windows system??


GreenCat
32-bit support

Function is defined as follows in WinUser.h.

#ifdef _WIN64

Omission

#else /* _WIN64 */
#define GetWindowLongPtrA   GetWindowLongA
#define GetWindowLongPtrW GetWindowLongW
#ifdef UNICODE
#define GetWindowLongPtr GetWindowLongPtrW
#else
#define GetWindowLongPtr GetWindowLongPtrA
#endif // !UNICODE
#define SetWindowLongPtrA   SetWindowLongA
#define SetWindowLongPtrW SetWindowLongW
#ifdef UNICODE
#define SetWindowLongPtr SetWindowLongPtrW
#else
#define SetWindowLongPtr SetWindowLongPtrA
#endif // !UNICODE
#endif /* _WIN64 */
Tags :

Stanley Roark
32-bit support
Thank you! I didn't know since I make programs in FASM. It's not that I don't have a C language, but to lazy to read all those includes ;)

Page view tracker