cemu-DS4Windows/DS4Tool/Program.cs
jays2kings 46e529f7be Fix for select an action window popping up when connecting a controller in some circumstances
DS4Updater: quicker startup, will only replace updater if the version is actually newer, smaller size
2014-07-09 13:18:11 -04:00

65 lines
2.2 KiB
C#

using System;
using System.Windows.Forms;
using System.Threading;
using System.Runtime.InteropServices;
using System.Diagnostics;
namespace ScpServer
{
static class Program
{
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool SetForegroundWindow(IntPtr hWnd);
[DllImport("user32.dll")]
private static extern IntPtr GetForegroundWindow();
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
System.Runtime.GCSettings.LatencyMode = System.Runtime.GCLatencyMode.LowLatency;
try
{
System.Diagnostics.Process.GetCurrentProcess().PriorityClass = System.Diagnostics.ProcessPriorityClass.High;
}
catch
{
// Ignore problems raising the priority.
}
bool createdNew = true;
using (Mutex mutex = new Mutex(true, "MyApplicationName", out createdNew))
{
if (createdNew)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new ScpForm());
}
else
{
Process current = Process.GetCurrentProcess();
foreach (Process process in Process.GetProcessesByName("DS4Windows"))
{
if (process.Id != current.Id)
{
SetForegroundWindow(process.MainWindowHandle);
if (GetForegroundWindow() != process.MainWindowHandle) //if tool is minimized to tray
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Alreadyrunning());
}
break;
}
}
}
}
}
}
}