如何在64位版本的Windows中调用SetWindowLong()? [英] How do I call SetWindowLong() in the 64-bit versions of Windows?

查看:997
本文介绍了如何在64位版本的Windows中调用SetWindowLong()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在头文件 WinUser.h 中,有一部分包含 SetWindowLong() 已定义。

In the header file WinUser.h, there is a part in which the constants of the second parameter of SetWindowLong() are defined.

// ...

#define GWL_WNDPROC         (-4)
#define GWL_HINSTANCE       (-6)
#define GWL_HWNDPARENT      (-8)
#define GWL_STYLE           (-16)
#define GWL_EXSTYLE         (-20)
#define GWL_USERDATA        (-21)
#define GWL_ID              (-12)

#ifdef _WIN64

#undef GWL_WNDPROC
#undef GWL_HINSTANCE
#undef GWL_HWNDPARENT
#undef GWL_USERDATA

#endif /* _WIN64 */

#define GWLP_WNDPROC        (-4)
#define GWLP_HINSTANCE      (-6)
#define GWLP_HWNDPARENT     (-8)
#define GWLP_USERDATA       (-21)
#define GWLP_ID             (-12)

// ...

但是,如果 _WIN64 已定义;并且它是在我的64位系统中定义的。

But they are right after undefined if _WIN64 is defined; and it is defined in my 64-bit system.

如您所见,还有一个 GWLP _ *** 常量集,但未在 SetWindowLong()页面中记录。

As you see, there is also a GWLP_*** set of constants, but they are not documented in the page of SetWindowLong().

为什么这些常量在x64系统中未定义?

在x64系统中调用 SetWindowLong()的另一种方法是什么?

Why are these constants undefined in x64 systems?
What is the alternative way of calling SetWindowLong() in x64 systems?

我的系统:

操作系统:Windows 7 Ultimate x64 SP1

IDE:Visual Studio 2012 Ultimate Update 3

My system:
OS: Windows 7 Ultimate x64 SP1
IDE: Visual Studio 2012 Ultimate Update 3

推荐答案

某些窗口数据值(例如,引用指针大小对象的值,例如窗口过程) x64版本中的64位。旧的 SetWindowLong() GetWindowLong()函数仅限于 DWORD 大小(32位)的大小以实现向后兼容性,并且Microsoft引入了新版本 SetWindowLongPtr() GetWindowLongPtr()允许您使用指针大小的值(32位构建为32位,而64位构建为64位)。

Some of the window data values (the ones that refer to "pointer sized" objects like the window procedure, for example) need to be 64 bit in an x64 build. The old SetWindowLong() and GetWindowLong() functions are limited to DWORD sized (32 bit) values for backwards compatibility, and Microsoft have introduced new versions, SetWindowLongPtr() and GetWindowLongPtr() that allow you to work with pointer-sized values (32 bit in a 32 bit build, and 64 bit in a 64 bit build).

这些天来建议您始终使用 SetWindowLongPtr() GWLP_xxx 常量,无论您要构建的是32位还是64位,但是在64位版本中,您需要使用新功能,因此,定义是#undefined,会导致生成错误,从而迫使您修复代码。

These days it is recommended that you always use SetWindowLongPtr() and the GWLP_xxx constants, whether you are building for 32 or 64 bit, but in a 64 bit build you need to use the new functions and so the defines are #undefined to cause build errors that force you to fix your code.

这篇关于如何在64位版本的Windows中调用SetWindowLong()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆