using UnityEngine;
using System.Collections;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System;
public class ExeControl
{
private IntPtr hwd;//窗口句柄
//显示窗口函数的命令
private const int SW_HIDE = 0; //隐藏窗口
private const int SW_NORMAL = 1;//正常显示
private const int SW_MAXIMIZE = 3; //最大化
private const int SW_SHOW = 5;//按切换前的状态显示
private const int SW_MINIMIZE = 6;// 最小化
private const int SW_SHOWDEFAULT = 10;// 按窗口原始值显示
[DllImport("User32.dll")]
private static extern IntPtr FindWindow(string lpClassName, string lpWindowName); // 根据名字寻找进程 ,返回进程的句柄
[DllImport("User32.dll")]
private static extern bool SetForegroundWindow(IntPtr hWnd); //将窗口置顶
[DllImport("User32.dll")]
private static extern bool ShowWindowAsync(IntPtr hWnd, int cmdShow);//动态不同线程间显示窗口
[DllImport("User32.dll")]
private static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);//显示窗口
public void replaceProcess()
{
hwd = FindWindow(null, "要切换的进程的名字"); // 获取要切换的进程的句柄
SetForegroundWindow(hwd);//将该进程窗口置顶
ShowWindowAsync(hwd, SW_SHOWDEFAULT);//显示窗口
}
}
关于进程间的通讯,可以参看下一篇博客:
http://blog.csdn.net/nizihabi/article/details/47104321