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

posted on 2015-06-04 15:25  电脑小白  阅读(1107)  评论(0编辑  收藏  举报