winform恢复窗口前端显示
2021-02-16 05:19
标签:current getc style class blog 添加 void color roc 1.添加系统DLL引用 2.得到窗口句柄 应用程序运行时 应用程序运行中 3.调用API winform恢复窗口前端显示 标签:current getc style class blog 添加 void color roc 原文地址:https://www.cnblogs.com/tian2008/p/8416891.html[DllImport("user32.dll")]
public static extern void SwitchToThisWindow(IntPtr hWnd, bool fAltTab);
Process instance = null;
Process current = Process.GetCurrentProcess();
Process[] processes = Process.GetProcessesByName(current.ProcessName);
//遍历与当前进程名称相同的进程列表
foreach (Process process in processes)
{
//如果实例已经存在则忽略当前进程
if (process.Id != current.Id)
{
//得到已经存在的进程
instance = process;
break;
}
}Process instance = Process.GetCurrentProcess();
SwitchToThisWindow(instance.MainWindowHandle, true);