Ian Boyd
Ian Boyd

Reputation: 257047

How to intercept a message sent to any TWinControl on my form?

I'm faced with the daunting task of having to intercept and handle the WM_GETOBJECT message whenever it is sent to any TWinControl on a Form.

Obviously i'd prefer not to have to individually subclass every control:

Is there a way to be involved in the handling of every message sent directly to a child control using SendMessage

Upvotes: 4

Views: 799

Answers (1)

Remy Lebeau
Remy Lebeau

Reputation: 598134

If you don't want to subclass each individual control (which is certainly an option, and one that can be simplified using interposer classes, for instance), then you can instead use a thread-specific WH_CALLWNDPROC or WH_CALLWNDPROCRET hook via the Win32 API SetWindowsHookEx() function. The hooks will tell you which HWND is receiving each message, and you don't need to implement the hooks in a DLL when hooking a thread in the same process as the hooker.

If you need the TWinControl* pointer for a given HWND, you can use the VCL's FindControl() function in the Vcl.Controls unit.

Upvotes: 7

Related Questions