GetWindowLongPtr function
Applies to: desktop apps only
Retrieves information about the specified window. The function also retrieves the value at a specified offset into the extra window memory.
Note To write code that is compatible with both 32-bit and 64-bit versions of Windows, use GetWindowLongPtr. When compiling for 32-bit Windows, GetWindowLongPtr is defined as a call to the GetWindowLong function.
Syntax
LONG_PTR WINAPI GetWindowLongPtr( __in HWND hWnd, __in int nIndex );
Parameters
- hWnd [in]
-
Type: HWND
A handle to the window and, indirectly, the class to which the window belongs.
- nIndex [in]
-
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 the size of an integer. To retrieve any other value, specify one of the following values.
Value Meaning - GWL_EXSTYLE
- -20
Retrieves the extended window styles.
- GWLP_HINSTANCE
- -6
Retrieves a handle to the application instance.
- GWLP_HWNDPARENT
- -8
Retrieves a handle to the parent window, if there is one.
- GWLP_ID
- -12
Retrieves the identifier of the window.
- GWL_STYLE
- -16
Retrieves the window styles.
- GWLP_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.
- GWLP_WNDPROC
- -4
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.
The following values are also available when the hWnd parameter identifies a dialog box.
Value Meaning - DWLP_DLGPROC
- DWLP_MSGRESULT + sizeof(LRESULT)
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
- 0
Retrieves the return value of a message processed in the dialog box procedure.
- DWLP_USER
- DWLP_DLGPROC + sizeof(DLGPROC)
Retrieves extra information private to the application, such as handles or pointers.
Return value
Type:
Type: LONG_PTR
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.
Requirements
|
Minimum supported client | Windows 2000 Professional |
|---|---|
|
Minimum supported server | Windows 2000 Server |
|
Header |
|
|
Library |
|
|
DLL |
|
|
Unicode and ANSI names | GetWindowLongPtrW (Unicode) and GetWindowLongPtrA (ANSI) |
See also
- Reference
- CallWindowProc
- RegisterClassEx
- SetParent
- SetWindowLongPtr
- WNDCLASSEX
- Conceptual
- Window Classes
Send comments about this topic to Microsoft
Build date: 2/3/2012
- 2/5/2012
- Vozzie
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 */
- 7/24/2009
- GreenCat
- 8/15/2010
- paulbassett13
- 7/28/2009
- Tycho
- 8/6/2009
- Stanley Roark
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??
- 7/24/2009
- Tycho
- 8/6/2009
- Stanley Roark