public bool HookProc(IntPtr wParam, IntPtr lParam, MouseStruct data) { switch (wParam.ToInt32()) { case NativeMethods.WM_MOUSEMOVE: if (CaptureMode == CaptureMode.Window) { SetFocusedWindow(WindowHelper.ChildFromPoint(Control.MousePosition)); } break; case NativeMethods.WM_LBUTTONDOWN: if (CaptureMode != CaptureMode.Unknown) { switch (CaptureMode) { case CaptureMode.Drag: isDragging = true; dragStartPosition = new Point(data.x, data.y); BeginDragCapture?.Invoke(this, dragStartPosition); break; case CaptureMode.Window: // TODO: Window Capture break; } return(true); } break; case NativeMethods.WM_LBUTTONUP: if (CaptureMode == CaptureMode.Drag && isDragging) { isDragging = false; var sw = new Stopwatch(); var dragEndPosition = new Point(data.x, data.y); EndDragCapture?.Invoke(this, dragEndPosition); RunCapture( RectangleEx.GetRectangle( dragStartPosition, dragEndPosition)); return(true); } else if (CaptureMode == CaptureMode.Window) { if (focusedWindow != IntPtr.Zero) { IntPtr captureHandle = focusedWindow; SetFocusedWindow(IntPtr.Zero); EndCapture(null /* ScreenCapture.Capture(captureHandle) */); } return(true); } break; } return(false); }