获取 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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 15:43:32  来源:igfitidea点击:

Get the WNDPROC for windows handle

c++windowsdelphiwinapi

提问by Salvador

Exist any Windows api function to retrieve the WNDPROCfor a Windows Handle?

是否存在任何 Windows api 函数来检索WNDPROCWindows 句柄?

Thanks in advance.

提前致谢。

回答by Vlad

Use GetWindowLongPtr(hwnd, GWLP_WNDPROC).

使用GetWindowLongPtr(hwnd, GWLP_WNDPROC)。

Caution: GetWindowLongPtr is actually #defined 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 #defined 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 本身是#defineGetWindowLongPtrA 或 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这篇帖子