原文链接 -> 传送门
函数功能:
GetWindowLongPtr 函数用于获取指定窗口的有关信息,该函数也获取在窗口额外存储空间的指定偏移量处的值。
注意:为了使代码同时兼容 32 位和 64 位版本的 Windows,请使用 GetWindowLongPtr 函数。当编译为 32 位时,GetWindowLongPtr 函数被定义为对 GetWindowLong 函数的调用。
API 函数原型:
注释:_In_ 说明该参数是输入的。
LONG WINAPI GetWindowLong( _In_ HWND hWnd, _In_ int nIndex );
参数解析:
|
参数 |
含义 |
||||||||||||||||||||||||
|
hWnd |
指向目标窗口的句柄,间接的指向窗口所属的窗口类 |
||||||||||||||||||||||||
|
nIndex |
1. 指定要获取的偏移量的值,并且值从 0 开始。有效值的范围从 0 到窗口额外存储空间的字节数减去一个整型数据所占的大小。要获取任意其他值,指定下列值之一:
|
返回值:
1. 如果函数调用成功,返回值为所需的值;
2. 如果函数调用失败,返回值为 0。获取有关错误的更多信息,请调用 GetLastError 函数;
3. 如果之前没有调用 SetWindowLong 或 SetWindowLongPtr 函数,对于窗口或类的额外存储空间,GetWindowLongPtr 函数的返回值为 0。
备注:
通过在函数 RegisterClassEx 函数中将结构 WNDCLASSEX 结构中的 cbWndExtra 成员指定为非 0 值来获取窗口额外存储空间。
需求:
|
Minimum supported client |
Windows 2000 专业版 [仅桌面应用程序] |
|
Minimum supported server |
Windows 2000 服务器版 [仅桌面应用程序] |
|
Header |
Winuser.h (包含于 Windows.h) |
|
Library |
User32.lib |
|
DLL |
User32.dll |
|
Unicode and ANSI names |
GetWindowLongPtrW (Unicode) 和 GetWindowLongPtrA (ANSI) |




