protected override IntPtr WndProc(IntPtr hwnd, int _msg, IntPtr wParam, IntPtr lParam, ref bool handled) { var msg = (WM)_msg; switch (msg) { case WM.WM_PAINT: { PAINTSTRUCT ps; var hdc = Import.BeginPaint(hwnd, out ps); Import.EndPaint(hwnd, ref ps); } RaiseEvent(new Win32EventArgs { RoutedEvent = Win32Event, Source = this, EventType = msg, }); handled = true; return IntPtr.Zero; case WM.WM_SIZE: RaiseEvent(new Win32EventArgs { RoutedEvent = Win32Event, Source = this, EventType = msg, X = lParam.Lo(), Y = lParam.Hi(), }); handled = true; return IntPtr.Zero; case WM.WM_DESTROY: RaiseEvent(new Win32EventArgs { RoutedEvent = Win32Event, Source = this, EventType = msg, }); handled = true; return IntPtr.Zero; case WM.WM_ERASEBKGND: handled = true; return IntPtr.Zero; #region MouseEvent case WM.WM_LBUTTONDOWN: RaiseEvent(new Win32EventArgs { RoutedEvent = Win32Event, Source = this, EventType = msg, X = lParam.Lo(), Y = lParam.Hi(), }); CaptureAndCursor(hwnd); handled = true; return IntPtr.Zero; case WM.WM_LBUTTONUP: RaiseEvent(new Win32EventArgs { RoutedEvent = Win32Event, Source = this, EventType = msg, X = lParam.Lo(), Y = lParam.Hi(), }); ReleaseMouse(); handled = true; return IntPtr.Zero; case WM.WM_RBUTTONDOWN: RaiseEvent(new Win32EventArgs { RoutedEvent = Win32Event, Source = this, EventType = msg, X = lParam.Lo(), Y = lParam.Hi(), }); CaptureAndCursor(hwnd); handled = true; return IntPtr.Zero; case WM.WM_RBUTTONUP: RaiseEvent(new Win32EventArgs { RoutedEvent = Win32Event, Source = this, EventType = msg, X = lParam.Lo(), Y = lParam.Hi(), }); ReleaseMouse(); handled = true; return IntPtr.Zero; case WM.WM_MBUTTONDOWN: RaiseEvent(new Win32EventArgs { RoutedEvent = Win32Event, Source = this, EventType = msg, X = lParam.Lo(), Y = lParam.Hi(), }); CaptureAndCursor(hwnd); handled = true; return IntPtr.Zero; case WM.WM_MBUTTONUP: RaiseEvent(new Win32EventArgs { RoutedEvent = Win32Event, Source = this, EventType = msg, X = lParam.Lo(), Y = lParam.Hi(), }); ReleaseMouse(); handled = true; return IntPtr.Zero; case WM.WM_MOUSEMOVE: if (Capture>0) { RaiseEvent(new Win32EventArgs { RoutedEvent = Win32Event, Source = this, EventType = msg, X = lParam.Lo(), Y = lParam.Hi(), }); } else { } Cursor = Cursors.Hand; handled = true; return IntPtr.Zero; case WM.WM_MOUSEWHEEL: RaiseEvent(new Win32EventArgs { RoutedEvent = Win32Event, Source = this, EventType = msg, Y = (short)wParam.Hi(), }); handled = true; return IntPtr.Zero; #endregion } return base.WndProc(hwnd, _msg, wParam, lParam, ref handled); }