Reputation: 1929
i have a c# powered windows form app and i want to run a exe inside it. that program is another seperate executable file. lets say that that exe is not a dot net app, but written in another language, does it matter ?
so i would want that program to lie inside my winforms, how can i do it?? Also, can i place it anywhere in the winforms? are there like properties already included by default? thanks. hage u tried doing these? if so what are the steps to take? thank you stackoverflow for making a nice developer community. i really cherish this
Upvotes: 3
Views: 16834
Reputation: 20424
You can do this by PInvoking SetParent()
:
[DllImport("user32.dll")]
static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
First you need to start the third party application within your application:
var clientApplication = Process.Start("PATH_TO_YOUR_EXECUTABLE");
then set its MainWindowHandle
to your main window handle:
SetParent(clientApplication.MainWindowHandle, YourMainWindowOrAContainerControl.Handle);
Upvotes: 6
Reputation: 31
[DllImport("user32.dll")]
static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
private void button1_Click(object sender, EventArgs e)
{
try
{
Process p = Process.Start(textBox1.Text);
p.WaitForInputIdle();
SetParent(p.MainWindowHandle, panel1.Handle);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
Reference to fardjad but it can only run small programs like notepad, firefox, safari
Upvotes: 3