200分求棘手問題解決方案.
問題是這樣的.偶做一個winform程序.生成exe文件.當第一次Run程序的時候啟動程序,當再次Run的時候(上次程序沒有結束),將上次Run的程序的主窗口提到最上層,
[DllImport( "user32.dll ", CharSet = CharSet.Auto)]
public static extern bool BringWindowToTop(IntPtr hwnd);
/// <summary>
/// 應用程式的主要進入點。
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Process inst = RunningInstance();
if (inst == null)
{
Application.Run(new EIPNotify());
}
else
{
BringWindowToTop(inst.MainWindowHandle);
}
//Application.Run(new EIPNotify());
}
public static Process RunningInstance()
{
Process current = Process.GetCurrentProcess();
Process[] processes = Process.GetProcessesByName(current.ProcessName);
foreach (Process process in processes)
{
if (process.ProcessNam