protected override void UpdateDisplayMode() { // Get the monitor Monitor monitor = GetMonitorOfWindow(); if (monitor == null) { Engine.Log.Warning("No monitor attached?", MessageSource.Win32); return; } switch (_mode) { case DisplayMode.Windowed: WindowStyles style = DetermineWindowStyle(); IntPtr res = User32.SetWindowLongPtr(_windowHandle, WindowLongFlags.GWL_STYLE, (IntPtr)style); if (res == IntPtr.Zero) { CheckError("Couldn't change display mode to windowed.", true); } if (_windowModeSize != null) { Size = (Vector2)_windowModeSize; _windowModeSize = null; } // Center window on screen. (This will also apply the SetWindowLongPtr changes, and remove the topmost status when exiting out of fullscreen) Position = monitor.Position + (new Vector2(monitor.Width, monitor.Height) / 2 - Size / 2); break; case DisplayMode.Fullscreen: IntPtr resp = User32.SetWindowLongPtr(_windowHandle, WindowLongFlags.GWL_STYLE, (IntPtr)FULLSCREEN_STYLE); if (resp == IntPtr.Zero) { CheckError("Couldn't change display mode to fullscreen, couldn't apply window style.", true); return; } bool successful = User32.SetWindowPos( _windowHandle, (IntPtr)HwndZOrder.HWND_NOTOPMOST, (int)monitor.Position.X, (int)monitor.Position.Y, monitor.Width, monitor.Height, WindowPositionFlags.SWP_NOACTIVATE | WindowPositionFlags.SWP_NOCOPYBITS | WindowPositionFlags.SWP_FRAMECHANGED ); if (!successful) { CheckError("Couldn't change display mode to fullscreen, couldn't apply window rect.", true); } // Center cursor on screen/window. User32.SetCursorPos((int)(monitor.Position.X + monitor.Width / 2), (int)(monitor.Position.Y + monitor.Height / 2)); break; } }