WPF不是基于消息响应的,WPF用的路由事件,如果想响应消息参考以下代码
-
C# code
-
private const int WM_MOUSEMOVE = 0x200; IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) { if (msg == WM_MOUSEMOVE) { //在这里添加鼠标移动的响应 handled = true; } return (new IntPtr(0)); } //窗口Loaded事件响应 private void Window_Loaded(object sender, RoutedEventArgs e) { IntPtr hwnd = new WindowInteropHelper(this).Handle; HwndSource hs = HwndSource.FromHwnd(hwnd); hs.AddHook(new HwndSourceHook(WndProc)); }