wpf 处理获取鼠标点击方法

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;
        }

原文地址:https://www.cnblogs.com/guiqiang/p/4551954.html