Пример #1
0
 public CaptureRegion(formCallBack fcb)
 {
     this.fcb = fcb;
     InitializeComponent();
     this.TopMost = true;
     this.Hide();
     _callback            = this.MouseMoveCallBack;
     this.BackColor       = Color.Aqua;
     this.TransparencyKey = Color.Aqua;
     this.Width           = 0;
     this.Height          = 0;
     _hook = MouseHook.SetWindowsHookEx(MouseHook.HookType.WH_MOUSE_LL, _callback, MouseHook.GetModuleHandle("user32"), 0);
     if (_hook == IntPtr.Zero)
     {
         throw new System.ComponentModel.Win32Exception();
     }
 }
Пример #2
0
 private IntPtr MouseMoveCallBack(int code, IntPtr wParam, IntPtr lParam)
 {
     if (code >= 0)
     {
         var WM_Code   = (MouseHook.WM_Codes)wParam;
         var mouseInfo = Marshal.PtrToStructure <MouseHook.MOUSEHOOKSTRUCT>(lParam);
         if (WM_Code == MouseHook.WM_Codes.WM_MOUSEMOVE)
         {
             OnMouseMove(mouseInfo);
         }
         if (WM_Code == MouseHook.WM_Codes.WM_LBUTTONDOWN)
         {
             OnLBtnClick();
         }
         if (WM_Code == MouseHook.WM_Codes.WM_LBUTTONUP)
         {
             OnLBtnUp();
         }
     }
     return(MouseHook.CallNextHookEx(IntPtr.Zero, code, wParam, lParam));
 }
Пример #3
0
 private void OnLBtnUp()
 {
     fcb(new Tuple <Point, Size>(new Point(this.Left, this.Top), Size));
     MouseHook.UnhookWindowsHookEx(_hook);
     this.Close();
 }