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

查看:40
本文介绍了如何在 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 被定义,它们就在 undefined 之后;它是在我的 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天全站免登陆