实现代码
const int WM_MOUSEMOVE = 0x0200;
private void Window_Loaded(object sender, RoutedEventArgs e)
{
HwndSource source = HwndSource.FromHwnd(new WindowInteropHelper(this).Handle);
source.AddHook(WndProc);
}
private static IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
switch (msg)
{
case WM_MOUSEMOVE:
Console.WriteLine("Mouse Move");
break;
default:
break;
}
return IntPtr.Zero;
}