using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.InteropServices;
namespace BjProject
{
static class Program
{
[DllImport("user32.dll")]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll ", SetLastError = true)]
static extern void SwitchToThisWindow(IntPtr hWnd, bool fAltTab);
[DllImport("user32.dll", EntryPoint = "ShowWindow", CharSet = CharSet.Auto)]
public static extern int ShowWindow(IntPtr hwnd, int nCmdShow);
public const int SW_RESTORE = 9;
public static IntPtr formhwnd;
///<summary>
/// 应用程序的主入口点。
///</summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
string proc = Process.GetCurrentProcess().ProcessName;
Process[] processes = Process.GetProcessesByName(proc);
if (processes.Length <= 1)
{
//Application.Run(new FrmMain1());
FrmLogon form = new FrmLogon();
form.ShowDialog();
if (form.DialogResult == DialogResult.OK)
{
form.Close();
form.Dispose();
Application.Run(new FrmMain());
}
else
{
Application.Exit();
}
}
else
{
for (int i = 0; i < processes.Length; i++)
{
if (processes[i].Id != Process.GetCurrentProcess().Id)
{
if (processes[i].MainWindowHandle.ToInt32() == 0)
{
formhwnd = FindWindow(null, "FrmMain");
ShowWindow(formhwnd, 1);
SwitchToThisWindow(formhwnd, true);
}
else
{
SwitchToThisWindow(processes[i].MainWindowHandle, true);
}
}
}
}
}
}
}