Skip to content

Commit 144382a

Browse files
committed
improved forwarding focus to an already running QL window when re-starting extraQL with enabled option to auto-start QL
1 parent 4e51f40 commit 144382a

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

readme.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ c:\program files (x86)\Steam\SteamApps\workshop\content\282440\539252269
1414
Changelog
1515
=========
1616

17+
Version 2.15
18+
---
19+
- improved forwarding focus to an already running QL window when re-starting extraQL with enabled option to auto-start QL
20+
1721
Version 2.14
1822
---
1923
- 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

source/MainForm.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace ExtraQL
1212
{
1313
public partial class MainForm : Form
1414
{
15-
public const string Version = "2.14";
15+
public const string Version = "2.15";
1616

1717
private readonly Config config;
1818
private readonly HttpServer server;
@@ -852,8 +852,12 @@ private void StartQuakeLive()
852852
if (procList.Length > 0)
853853
{
854854
// bring existing QL window to front and activate it
855-
Win32.SetWindowPos(procList[0].MainWindowHandle, Win32.HWND_TOPMOST, 0, 0, 0, 0, Win32.SWP_SHOWWINDOW | Win32.SWP_NOSIZE | Win32.SWP_NOMOVE);
856-
Win32.SetWindowPos(procList[0].MainWindowHandle, Win32.HWND_NOTOPMOST, 0, 0, 0, 0, Win32.SWP_SHOWWINDOW | Win32.SWP_NOSIZE | Win32.SWP_NOMOVE);
855+
var hWnd = procList[0].MainWindowHandle;
856+
Win32.ShowWindow(hWnd, Win32.SW_SHOWNORMAL);
857+
Win32.SetForegroundWindow(hWnd);
858+
Win32.SetCapture(hWnd);
859+
Win32.SetFocus(hWnd);
860+
Win32.SetActiveWindow(hWnd);
857861
}
858862
else
859863
{

source/Win32.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,28 @@ public static class Win32
4343
[DllImport("user32.dll")]
4444
public static extern bool ShowWindow(IntPtr handle, int flags);
4545

46+
[DllImport("user32.dll")]
47+
public static extern bool SetActiveWindow(IntPtr handle);
48+
4649
[DllImport("user32.dll")]
4750
public static extern bool SetForegroundWindow(IntPtr handle);
4851

52+
[DllImport("user32.dll")]
53+
public static extern bool SetFocus(IntPtr handle);
54+
55+
[DllImport("user32.dll")]
56+
public static extern bool SetCapture(IntPtr handle);
57+
58+
[DllImport("user32.dll")]
59+
public static extern bool EnableWindow(IntPtr handle, bool enable);
60+
4961
public delegate bool EnumWindowProc(IntPtr hWnd, IntPtr lParam);
5062

5163
public static int HWND_TOPMOST = -1;
5264
public static int HWND_NOTOPMOST = -2;
5365

5466
public const int WM_ACTIVATE = 0x0006;
67+
public const int WM_NCACTIVATE = 0x0086;
5568
public const int WM_SETREDRAW = 0x000B;
5669
public const int WM_CLOSE = 0x0010;
5770
public const int WM_SHOWWINDOW = 0x0018;
@@ -69,6 +82,11 @@ public static class Win32
6982
public const int WM_SYSKEYDOWN = 0x0104;
7083
public const int WM_SYSKEYUP = 0x0105;
7184

85+
public const int SW_SHOWNORMAL = 1;
86+
87+
public const int WA_ACTIVE = 1;
88+
public const int WA_CLICKACTIVE = 2;
89+
7290
public const int SWP_NOSIZE = 0x0001;
7391
public const int SWP_NOMOVE = 0x0002;
7492
public const int SWP_NOACTIVATE = 0x0010;

0 commit comments

Comments
 (0)