Skip to content

Commit 717f7b4

Browse files
committed
1.5.9
[fix] Focused app has not be recognized as running app
1 parent 96c3b3c commit 717f7b4

File tree

6 files changed

+49
-6
lines changed

6 files changed

+49
-6
lines changed

Source/HDRProfile/HDRProfileHandler.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -291,8 +291,7 @@ private void StartApplication(ApplicationItem application)
291291
Process process = new Process();
292292
process.StartInfo = new ProcessStartInfo(application.ApplicationFilePath);
293293
process.Start();
294-
Stopwatch stopwatch = new Stopwatch();
295-
stopwatch.Start();
294+
Tools.BringMainWindowToFront(process.ProcessName);
296295
System.Threading.Thread.Sleep(500);
297296
}
298297
catch (Exception ex)
@@ -529,7 +528,7 @@ private void RestartProcess(ApplicationItem application)
529528
return;
530529
}
531530
Process.GetProcessesByName(application.ApplicationName).ToList().ForEach(p => p.Kill());
532-
System.Threading.Thread.Sleep(2000);
531+
System.Threading.Thread.Sleep(1500);
533532
Process proc = new Process();
534533
StartApplication(application);
535534
}

Source/HDRProfile/ProcessWatcher.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ private void WatchProcessLoop()
160160
{
161161
UpdateApplications();
162162
bool oldIsOneRunning = OneProcessIsRunning;
163-
bool newIsOneRunning = _applications.Any(a => a.Value == ApplicationState.Running);
163+
bool newIsOneRunning = _applications.Any(a => a.Value == ApplicationState.Running ||a.Value == ApplicationState.Focused);
164164
OneProcessIsRunning = newIsOneRunning;
165165
if (oldIsOneRunning != newIsOneRunning)
166166
{

Source/HDRProfile/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,5 @@
5252
// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
5353
// indem Sie "*" wie unten gezeigt eingeben:
5454
// [assembly: AssemblyVersion("1.0.*")]
55-
[assembly: AssemblyVersion("1.5.8.0")]
56-
[assembly: AssemblyFileVersion("1.5.8.0")]
55+
[assembly: AssemblyVersion("1.5.9.0")]
56+
[assembly: AssemblyFileVersion("1.5.9.0")]

Source/HDRProfile/Tools.cs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,21 @@
22
using Microsoft.Win32;
33
using System;
44
using System.Collections.Generic;
5+
using System.Diagnostics;
6+
using System.Linq;
57
using System.Reflection;
68

79
namespace HDRProfile
810
{
11+
enum ShowWindowEnum
12+
{
13+
Hide = 0,
14+
ShowNormal = 1, ShowMinimized = 2, ShowMaximized = 3,
15+
Maximize = 3, ShowNormalNoActivate = 4, Show = 5,
16+
Minimize = 6, ShowMinNoActivate = 7, ShowNoActivate = 8,
17+
Restore = 9, ShowDefault = 10, ForceMinimized = 11
18+
};
19+
920
public static class Tools
1021
{
1122
public static void SetAutoStart(string applicationName, string filePath, bool autostart)
@@ -46,6 +57,39 @@ public static Version ApplicationVersion
4657

4758
public static Logs Logs = new Logs($"{System.AppDomain.CurrentDomain.BaseDirectory}HDRProfile.log", "HDRPProfile", Assembly.GetExecutingAssembly().GetName().Version.ToString(), true);
4859

60+
[System.Runtime.InteropServices.DllImport("user32.dll")]
61+
[return: System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.Bool)]
62+
private static extern bool ShowWindow(IntPtr hWnd, ShowWindowEnum flags);
63+
64+
[System.Runtime.InteropServices.DllImport("user32.dll")]
65+
private static extern int SetForegroundWindow(IntPtr hwnd);
66+
67+
68+
public static void BringMainWindowToFront(string processName)
69+
{
70+
// get the process
71+
Process bProcess = Process.GetProcessesByName(processName).FirstOrDefault();
72+
73+
// check if the process is running
74+
if (bProcess != null)
75+
{
76+
// check if the window is hidden / minimized
77+
if (bProcess.MainWindowHandle == IntPtr.Zero)
78+
{
79+
// the window is hidden so try to restore it before setting focus.
80+
ShowWindow(bProcess.Handle, ShowWindowEnum.Restore);
81+
}
82+
83+
// set user the focus to the window
84+
SetForegroundWindow(bProcess.MainWindowHandle);
85+
}
86+
else
87+
{
88+
// the process is not running, so start it
89+
Process.Start(processName);
90+
}
91+
}
92+
4993
}
5094

5195

Source/Release_Any/HDRProfile.exe

1 KB
Binary file not shown.
0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)