From 10112da9764f80cef4d6e021aa72f1b2034c232f Mon Sep 17 00:00:00 2001 From: Fraser Date: Fri, 21 Feb 2014 19:46:13 +0000 Subject: [PATCH] Respond to WM_SETCURSOR messages. Calling SetCursor on mouse moves is not enough, we need to respond to SETCURSOR messages. If we have a custom cursor we need to call SetCursor and then NOT call DefWindowProc, otherwise we just call DefWindowProc for the forms default cursor. --- Source/OpenTK/Platform/Windows/WinGLNative.cs | 32 +++++++++++++++---- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/Source/OpenTK/Platform/Windows/WinGLNative.cs b/Source/OpenTK/Platform/Windows/WinGLNative.cs index 6fc532d1..5e41c25d 100644 --- a/Source/OpenTK/Platform/Windows/WinGLNative.cs +++ b/Source/OpenTK/Platform/Windows/WinGLNative.cs @@ -388,6 +388,17 @@ namespace OpenTK.Platform.Windows } } + private bool HandleSetCursor(IntPtr handle, WindowMessage message, IntPtr wParam, IntPtr lParam) + { + if (cursor != MouseCursor.Default) + { + Functions.SetCursor(curson_handle); + return true; + } + + return false; + } + void HandleChar(IntPtr handle, WindowMessage message, IntPtr wParam, IntPtr lParam) { char c; @@ -486,11 +497,6 @@ namespace OpenTK.Platform.Windows mouse_last_timestamp = timestamp; } - if (cursor != MouseCursor.Default) - { - Functions.SetCursor(curson_handle); - } - if (mouse_outside_window) { // Once we receive a mouse move event, it means that the mouse has @@ -660,6 +666,8 @@ namespace OpenTK.Platform.Windows IntPtr WindowProcedure(IntPtr handle, WindowMessage message, IntPtr wParam, IntPtr lParam) { + bool result = false; + switch (message) { #region Size / Move / Style events @@ -693,6 +701,10 @@ namespace OpenTK.Platform.Windows HandleSize(handle, message, wParam, lParam); break; + case WindowMessage.SETCURSOR: + result = HandleSetCursor(handle, message, wParam, lParam); + break; + #endregion #region Input events @@ -779,7 +791,15 @@ namespace OpenTK.Platform.Windows #endregion } - return Functions.DefWindowProc(handle, message, wParam, lParam); + if (result) + { + // Return TRUE + return new IntPtr(1); + } + else + { + return Functions.DefWindowProc(handle, message, wParam, lParam); + } } private void EnableMouseTracking()