diff options
Diffstat (limited to 'Program.cs')
-rw-r--r-- | Program.cs | 32 |
1 files changed, 29 insertions, 3 deletions
@@ -1,21 +1,47 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; +using System.Runtime.InteropServices; +using System.Threading; using System.Windows.Forms; namespace com.clusterrr.hakchi_gui { static class Program { + [DllImport("user32.dll")] + [return: MarshalAs(UnmanagedType.Bool)] + static extern bool SetForegroundWindow(IntPtr hWnd); + /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main() { - Application.EnableVisualStyles(); - Application.SetCompatibleTextRenderingDefault(false); - Application.Run(new MainForm()); + bool createdNew = true; + using (Mutex mutex = new Mutex(true, "hakchi2", out createdNew)) + { + if (createdNew) + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new MainForm()); + } + else + { + Process current = Process.GetCurrentProcess(); + foreach (Process process in Process.GetProcessesByName(current.ProcessName)) + { + if (process.Id != current.Id) + { + SetForegroundWindow(process.MainWindowHandle); + break; + } + } + } + } } } } |