调用外边exe,判断:
如果未启动则启动,这个知道
如果已启动则将exe窗体变成激活窗体,显示在最前面,如何实现?
 Process[] myprocess = Process.GetProcessesByName("InfoColl");
 if (myprocess.Length > 0)
 {
    // myprocess[0].CloseMainWindow();//这样处理不好,想改成激活最大化,如何实现????
    //myprocess[0].Close();   }
 else
 {
     Process.Start("InfoColl.exe");
 }

解决方案 »

  1.   

    // For Windows Mobile, replace user32.dll with coredll.dll
    [DllImport("user32.dll")]
    [return: MarshalAs(UnmanagedType.Bool)]
    static extern bool SetForegroundWindow(IntPtr hWnd);
      

  2.   

    [DllImport("user32.dll")]
    [return: MarshalAs(UnmanagedType.Bool)]
    static extern bool ShowWindow(IntPtr hWnd, ShowWindowCommands nCmdShow);
      

  3.   


    public const uint WM_SYSCOMMAND = 0x0112;
    public const uint SC_MAXIMIZE = 0xF030;[DllImport("user32.dll")]
    public static extern int SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);[DllImport("user32.dll")]
    public static extern void SwitchToThisWindow(IntPtr hWnd, bool fAltTab);if (myprocess.Length > 0)
    {
    IntPtr handle = myprocess[0].MainWindowHandle;
    SendMessage(handle, WM_SYSCOMMAND, new IntPtr(SC_MAXIMIZE), IntPtr.Zero); // 最大化
    SwitchToThisWindow(handle, true); // 激活
    }