this.SourceInitialized += new EventHandler(win_SourceInitialized); //这里写在构造函数里
void win_SourceInitialized(object sender, EventArgs e)
{ HwndSource hwndSource = PresentationSource.FromVisual(this) as HwndSource; if (hwndSource != null) { hwndSource.AddHook(new HwndSourceHook(WindowProc)); } }
protected virtual IntPtr WindowProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{ switch (msg) { case 0x0201: //MessageBox.Show("鼠标按下!"); Count = 0; break; } return IntPtr.Zero; }