winform恢復窗口前端顯示
阿新 • • 發佈:2018-02-05
and 存在 引用 style extern etc use spa 進程
1.添加系統DLL引用
[DllImport("user32.dll")] public static extern void SwitchToThisWindow(IntPtr hWnd, bool fAltTab);
2.得到窗口句柄
應用程序運行時
Process instance = null;
Process current = Process.GetCurrentProcess(); Process[] processes = Process.GetProcessesByName(current.ProcessName); //遍歷與當前進程名稱相同的進程列表 foreach (Process process inprocesses) { //如果實例已經存在則忽略當前進程 if (process.Id != current.Id) { //得到已經存在的進程 instance = process;
break;
}
}
應用程序運行中
Process instance = Process.GetCurrentProcess();
3.調用API
SwitchToThisWindow(instance.MainWindowHandle, true);
winform恢復窗口前端顯示