获取 Windows 句柄的 WNDPROC
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4341303/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Get the WNDPROC for windows handle
提问by Salvador
Exist any Windows api function to retrieve the WNDPROC
for a Windows Handle?
是否存在任何 Windows api 函数来检索WNDPROC
Windows 句柄?
Thanks in advance.
提前致谢。
回答by Vlad
Use GetWindowLongPtr(hwnd, GWLP_WNDPROC).
使用GetWindowLongPtr(hwnd, GWLP_WNDPROC)。
Caution: GetWindowLongPtr is actually #define
d to GetWindowLong for 32-bit systems, so in order to import it in Delphi you might need to use GetWindowLong instead. As well, GetWindowLongPtr itself is #define
d to either GetWindowLongPtrA or GetWindowLongPtrW (for non-unicode and unicode targets), so again you might need to choose the right name manually for Delphi if the import system there is not really smart.
注意:#define
对于 32 位系统,GetWindowLongPtr 实际上是 GetWindowLong 的 d,因此为了在 Delphi 中导入它,您可能需要改用 GetWindowLong。同样,GetWindowLongPtr 本身是#define
GetWindowLongPtrA 或 GetWindowLongPtrW(对于非 unicode 和 unicode 目标)的 d,因此如果导入系统不是真正智能,您可能需要再次为 Delphi 手动选择正确的名称。
Remember that if you are going to call the obtained window proc, you should do it using CallWindowProc. Thanks to @In silico for the hint.
请记住,如果您要调用获得的窗口过程,您应该使用CallWindowProc 来完成。感谢@In silico 的提示。
Please note that the value which is returned is not always the real pointer to the window procedure. Sometimes it's just a kind of handle which is recognized and correctly processed by CallWindowProc
. For example, you'll not get the real function pointer if your application is ANSI, but the window belongs to a Unicode component (or vice versa). See this posting in The Old New Thingfor more details.
请注意,返回的值并不总是指向窗口过程的真正指针。有时它只是一种被CallWindowProc
. 例如,如果您的应用程序是 ANSI,您将无法获得真正的函数指针,但窗口属于 Unicode 组件(反之亦然)。有关更多详细信息,请参阅The Old New Thing中的这篇帖子。