From 2ddd555aafdc699604c909dd42644b83de90621a Mon Sep 17 00:00:00 2001 From: "Stefanos A." Date: Fri, 20 Dec 2013 08:42:36 +0100 Subject: [PATCH] Simplify ProcessEvents implementation Instead of combining PeekMessage+GetMessage, we can simply call PeekMessage(Remove) to achieve the same effect. This also allows us to remove the IsIdle property, which is no longer used anywhere. --- Source/OpenTK/Platform/Windows/API.cs | 14 +++++++++++++- Source/OpenTK/Platform/Windows/WinGLNative.cs | 24 +----------------------- 2 files changed, 14 insertions(+), 24 deletions(-) diff --git a/Source/OpenTK/Platform/Windows/API.cs b/Source/OpenTK/Platform/Windows/API.cs index b9107d7..c05398e 100644 --- a/Source/OpenTK/Platform/Windows/API.cs +++ b/Source/OpenTK/Platform/Windows/API.cs @@ -349,7 +349,7 @@ namespace OpenTK.Platform.Windows [System.Security.SuppressUnmanagedCodeSecurity] [DllImport("User32.dll"), CLSCompliant(false)] [return: MarshalAs(UnmanagedType.Bool)] - internal static extern bool PeekMessage(ref MSG msg, IntPtr hWnd, int messageFilterMin, int messageFilterMax, int flags); + internal static extern bool PeekMessage(ref MSG msg, IntPtr hWnd, int messageFilterMin, int messageFilterMax, PeekMessageFlags flags); #endregion @@ -4028,6 +4028,18 @@ namespace OpenTK.Platform.Windows #endregion + #region PeekMessageFlags + + [Flags] + enum PeekMessageFlags : uint + { + NoRemove = 0, + Remove = 1, + NoYield = 2 + } + + #endregion + #region ShowWindowCommand /// diff --git a/Source/OpenTK/Platform/Windows/WinGLNative.cs b/Source/OpenTK/Platform/Windows/WinGLNative.cs index aae5d10..ccdcbd3 100644 --- a/Source/OpenTK/Platform/Windows/WinGLNative.cs +++ b/Source/OpenTK/Platform/Windows/WinGLNative.cs @@ -583,19 +583,6 @@ namespace OpenTK.Platform.Windows #endregion - #region IsIdle - - bool IsIdle - { - get - { - MSG message = new MSG(); - return !Functions.PeekMessage(ref message, window.Handle, 0, 0, 0); - } - } - - #endregion - #region CreateWindow IntPtr CreateWindow(int x, int y, int width, int height, string title, GameWindowFlags options, DisplayDevice device, IntPtr parentHandle) @@ -1217,20 +1204,11 @@ namespace OpenTK.Platform.Windows #region public void ProcessEvents() - private int ret; MSG msg; public void ProcessEvents() { - while (!IsIdle) + while (Functions.PeekMessage(ref msg, window.Handle, 0, 0, PeekMessageFlags.Remove)) { - ret = Functions.GetMessage(ref msg, window.Handle, 0, 0); - if (ret == -1) - { - throw new PlatformException(String.Format( - "An error happened while processing the message queue. Windows error: {0}", - Marshal.GetLastWin32Error())); - } - Functions.TranslateMessage(ref msg); Functions.DispatchMessage(ref msg); } -- 2.7.4