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(); /// /// The main entry point for the application. /// [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; } } } } } } }