
Untitled
By: a guest on
Jul 29th, 2012 | syntax:
None | size: 0.92 KB | hits: 19 | expires: Never
How to open process within Windows form
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
private void button1_Click(object sender, EventArgs e)
{
Process p = Process.Start("mstsc.exe", @"c:VPN4.rdp");
Thread.Sleep(3000);
p.StartInfo.CreateNoWindow = true; // new
SetParent(p.MainWindowHandle, this.panel1.Handle);
p.StartInfo.WindowStyle = ProcessWindowStyle.Maximized; //new
}
private void toolStripButton1_Click(object sender, EventArgs e)
{
ProcessStartInfo info = new ProcessStartInfo();
info.FileName = "notepad";
info.UseShellExecute = true;
var process = Process.Start(info);
Thread.Sleep(2000);
SetParent(process.MainWindowHandle, this.Handle);
}
ProcessStartInfo info = new ProcessStartInfo();
info.FileName = "notepad";
info.UseShellExecute = true;
Process.Start(info);