开发者

How i can cast a WNDPROC to a TWndMethod

How i can cast a WNDPROC to开发者_如何学运维 a TWndMethod

so far i try this but give me a invalid typecast error.

 TWndMethod(Pointer(GetWindowLong(FHandle, GWL_WNDPROC)));


If you want to subclass a window handle (using SetWindowLong) to process window messages in TWndMethod function, you should not cast the value returned by GetWindowLong(FHandle, GWL_WNDPROC) to TWndMethod. You should use MakeObjectInstance function to obtain a value that can be passed to SetWindowLong instead. Read Sertac Akuyz answer for a general idea.

Note that the need to subclass a window handle is very rare in Delphi applications. Delphi provides several other ways to interfere into window message processing, they are more simple and safe.


You've got two problems here. First, GetWindowLong doesn't give you the actual WndProc, but a handle to it.

Second, TWndMethod is defined as procedure(var Message: TMessage) of object; It's a method pointer, not a function pointer, so you can't cast a normal pointer to it. What exactly are you trying to do?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜