using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Diagnostics;
namespace outprocessinform
{
public partial class Form1 : Form
{
[DllImport("User32.dll", EntryPoint = "SetParent")]
private static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
[DllImport("user32.dll", EntryPoint = "ShowWindow")]
private static extern int ShowWindow(IntPtr hwnd, int nCmdShow);
public Form1()
{
InitializeComponent();
string fexePath = @"cmd.exe"; // 外部exe位置
Process p = new Process();
p.StartInfo.FileName = fexePath;
p.StartInfo.Arguments = args;
p.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
p.Start();
while (p.MainWindowHandle.ToInt32() == 0)
{
System.Threading.Thread.Sleep(100);
}
SetParent(p.MainWindowHandle, this.Handle);
ShowWindow(p.MainWindowHandle, (int)ProcessWindowStyle.Maximized);
}
}
}