diff --git a/readme.md b/readme.md index dbd2cc8..2dbb654 100644 --- a/readme.md +++ b/readme.md @@ -14,6 +14,10 @@ c:\program files (x86)\Steam\SteamApps\workshop\content\282440\539252269 Changelog ========= +Version 2.15 +--- +- improved forwarding focus to an already running QL window when re-starting extraQL with enabled option to auto-start QL + Version 2.14 --- - When option "Auto-Start QL" is active and you try to start a 2nd extraQL, extraQL will now bring the QL window to the foreground diff --git a/source/MainForm.cs b/source/MainForm.cs index 844a40a..79cf47e 100644 --- a/source/MainForm.cs +++ b/source/MainForm.cs @@ -12,7 +12,7 @@ namespace ExtraQL { public partial class MainForm : Form { - public const string Version = "2.14"; + public const string Version = "2.15"; private readonly Config config; private readonly HttpServer server; @@ -852,8 +852,12 @@ private void StartQuakeLive() if (procList.Length > 0) { // bring existing QL window to front and activate it - Win32.SetWindowPos(procList[0].MainWindowHandle, Win32.HWND_TOPMOST, 0, 0, 0, 0, Win32.SWP_SHOWWINDOW | Win32.SWP_NOSIZE | Win32.SWP_NOMOVE); - Win32.SetWindowPos(procList[0].MainWindowHandle, Win32.HWND_NOTOPMOST, 0, 0, 0, 0, Win32.SWP_SHOWWINDOW | Win32.SWP_NOSIZE | Win32.SWP_NOMOVE); + var hWnd = procList[0].MainWindowHandle; + Win32.ShowWindow(hWnd, Win32.SW_SHOWNORMAL); + Win32.SetForegroundWindow(hWnd); + Win32.SetCapture(hWnd); + Win32.SetFocus(hWnd); + Win32.SetActiveWindow(hWnd); } else { diff --git a/source/Win32.cs b/source/Win32.cs index e258d88..d549391 100644 --- a/source/Win32.cs +++ b/source/Win32.cs @@ -43,15 +43,28 @@ public static class Win32 [DllImport("user32.dll")] public static extern bool ShowWindow(IntPtr handle, int flags); + [DllImport("user32.dll")] + public static extern bool SetActiveWindow(IntPtr handle); + [DllImport("user32.dll")] public static extern bool SetForegroundWindow(IntPtr handle); + [DllImport("user32.dll")] + public static extern bool SetFocus(IntPtr handle); + + [DllImport("user32.dll")] + public static extern bool SetCapture(IntPtr handle); + + [DllImport("user32.dll")] + public static extern bool EnableWindow(IntPtr handle, bool enable); + public delegate bool EnumWindowProc(IntPtr hWnd, IntPtr lParam); public static int HWND_TOPMOST = -1; public static int HWND_NOTOPMOST = -2; public const int WM_ACTIVATE = 0x0006; + public const int WM_NCACTIVATE = 0x0086; public const int WM_SETREDRAW = 0x000B; public const int WM_CLOSE = 0x0010; public const int WM_SHOWWINDOW = 0x0018; @@ -69,6 +82,11 @@ public static class Win32 public const int WM_SYSKEYDOWN = 0x0104; public const int WM_SYSKEYUP = 0x0105; + public const int SW_SHOWNORMAL = 1; + + public const int WA_ACTIVE = 1; + public const int WA_CLICKACTIVE = 2; + public const int SWP_NOSIZE = 0x0001; public const int SWP_NOMOVE = 0x0002; public const int SWP_NOACTIVATE = 0x0010;