static class Program
{
[DllImport("User32.dll")]
private static extern bool ShowWindowAsync(IntPtr hWnd, int cmdShow);
[DllImport("User32.dll")]
private static extern bool SetForegroundWindow(IntPtr hWnd);
[DllImport("User32.dll")]
private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
private const int WS_SHOWNORMAL = 1;
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
bool MutexWasCreated;
Mutex MyMutex = new Mutex(true, "OCRServer", out MutexWasCreated);
if (MutexWasCreated)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new FrmMain());
MyMutex.WaitOne();
}
else
{
//“智能识别”是窗体的标题名称
IntPtr ptr = FindWindow(null, "智能识别");
if (ptr != IntPtr.Zero)
{
ShowWindowAsync(ptr, WS_SHOWNORMAL);
SetForegroundWindow(ptr);
}
}
}
}
C# 单实例运行控制
最新推荐文章于 2024-04-28 17:13:31 发布