[System.Runtime.InteropServices.DllImportAttribute("User32.dll")]
private static extern bool ShowWindowAsync(IntPtr hWnd, int cmdShow);
/// <summary>
/// 该函数将创建指定窗口的线程设置到前台,并且激活该窗口。键盘输入转向该窗口,并为用户改各种可视的记号。系统给创建前台窗口的线程分配的权限稍高于其他线程。
/// </summary>
/// <param name="hWnd">将被激活并被调入前台的窗口句柄。</param>
/// <returns>如果窗口设入了前台,返回值为非零;如果窗口未被设入前台,返回值为零。</returns>
[System.Runtime.InteropServices.DllImportAttribute("User32.dll")]
private static extern bool SetForegroundWindow(IntPtr hWnd);
private const int WS_SHOWNORMAL = 1;
private const int WS_SHOWMAXIMIZED = 3;
public static System.Diagnostics.Process RunningInstance()
{
System.Diagnostics.Process[] processes = System.Diagnostics.Process.GetProcessesByName("RS5000");
foreach (System.Diagnostics.Process process in processes)
{
return process;
}
return null;
}
public static void HandleRunningInstance(System.Diagnostics.Process instance)
{
ShowWindowAsync(instance.MainWindowHandle, WS_SHOWMAXIMIZED); //显示,可以注释掉
SetForegroundWindow(instance.MainWindowHandle); //放到前端
}
public static void Main()
{
System.Diagnostics.Process instance = RunningInstance();
if (instance != null)
{
HandleRunningInstance(instance);
}
}