/// <summary>
/// 0-关闭窗口 1-正常大小显示 2最小化窗口 3-最大化窗口
/// </summary>
/// <param name="hwnd"></param>
/// <param name="nCmdShow"></param>
/// <returns></returns>
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
public static extern int ShowWindow(IntPtr hwnd, int nCmdShow);
/// <summary>
/// 显示程序
/// </summary>
/// <param name="hwnd">窗口句柄</param>
/// <param name="nCmdshow">0-关闭窗口 1-正常大小显示 2最小化窗口 3-最大化窗口
</param>
/// <returns></returns>
public int DisPlayWindow(IntPtr hwnd, int nCmdshow)
{
return ShowWindow(hwnd, nCmdshow);
}
public Process Run(string exeName)
{
return Process.Start(exeName);
}
IntPtr hWnd = IntPtr.Zero;
Process process=null;
bool IsMini = true;
int nCmdshow = 1;
private void button1_Click(object sender, EventArgs e)
{
//获取句柄
if (process == null)
{
string exeName = Application.StartupPath + @"\CCD\CameraVision.exe";
//创建启动进程信息
process = Run(exeName);
}
else
{
if (IsMini)
{
DisPlayWindow(process.MainWindowHandle, 1);
IsMini = false;
}
else
{
DisPlayWindow(process.MainWindowHandle, 2);
IsMini = true;
}
}
if(process!=null && !process.HasExisted)
{
process.kill();
}
}
C#启用外部程序,同时隐藏外部程序窗体
于 2022-12-08 09:28:34 首次发布