Skip to content

Commit

Permalink
improved forwarding focus to an already running QL window when re-st…
Browse files Browse the repository at this point in the history
…arting extraQL with enabled option to auto-start QL
  • Loading branch information
PredatH0r committed Nov 26, 2015
1 parent 4e51f40 commit 144382a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
4 changes: 4 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 7 additions & 3 deletions source/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
{
Expand Down
18 changes: 18 additions & 0 deletions source/Win32.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 144382a

Please sign in to comment.