[STAThread]
static void Main()
{
Mutex mt = new Mutex(true, "MutexInstance");
if (!mt.WaitOne(0, false))
{
IntPtr hTray = FindWindow(null, "Mutex使用测试");
ShowWindow(hTray, 9);
SetForegroundWindow(hTray);
return;
}
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form3());
}
[DllImport("user32.dll", EntryPoint = "FindWindow")]
static extern IntPtr FindWindow(string ClassName, string WindowName);
[DllImport("user32.dll", EntryPoint = "ShowWindow")]
static extern Boolean ShowWindow(IntPtr hwnd, int nCmdShow);
[DllImport("user32.dll", EntryPoint = "SetForegroundWindow")]
static extern Boolean SetForegroundWindow(IntPtr hwnd);