[DllImport("User32.dll")]
private static extern bool SetForegroundWindow(IntPtr handle);
[DllImport("User32.dll")]
private static extern bool ShowWindow(IntPtr handle, int nCmdShow);
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
if(isRunningAlready())
{
string exe_name = AppDomain.CurrentDomain.FriendlyName.Replace(".exe", "").Replace(".EXE", ""
Process[] procList = Process.GetProcessesByName(exe_name);
BringProcessToFront(procList)
return;
}
Application.Run(new MainForm());
}
public static void BringProcessToFront(System.Diagnostics.Process[] processes)
{
foreach (System.Diagnostics.Process process in processes)
{
IntPtr handle = process.MainWindowHandle;
ShowWindow(handle, 1);
SetForegroundWindow(handle);
}
}
,当窗口可见且处于非活动状态时,此代码工作正常,但在程序中隐藏在任务栏图标中的功能不起作用。我做错了什么? 预先感谢。