开发者

HWnd Message Hook in WinForms?

开发者 https://www.devze.com 2023-03-31 07:58 出处:网络
What is the WinForms equivalent to the following line of WPF code? HwndSource.FromHwnd(_windowHandle).AddHook(HwndSourceHookH开发者_Go百科andler);

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.

0

精彩评论

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