HWnd Message Hook in WinForms?
What is the WinForms equivalent to the following line of WPF code?
HwndSource.FromHwnd(_windowHandle).AddHook(HwndSourceHookH开发者_Go百科andler);
In WinForms, you'd typically override WndProc in the control/Form in question. Since every control is effectively a HWND
, you don't need the HwndSource
style of hooking.
If you want to setup a Hook in C#, you can follow the guidelines in How to set a Windows hook in Visual C# .NET.
Inside your own process, you can use the Application.AddMessageFilter method to listen to specific events before they are dispatched anywhere. This doesn't work between processes.
I found this while searching for an answer to one of my questions about handling of mouse events between parent and child controls.
精彩评论