How can I take over, another running application within a panel of my C# program?

118 views Asked by At

What i'm trying to do is to take over another running application and attach it to a panel in my Form, somthing like this:

   private void button1_Click(object sender, EventArgs e)
    {
        Process p = Process.Start("notepad.exe");
        Thread.Sleep(500); // Allow the process to open it's window
        SetParent(p.MainWindowHandle, panel1.Handle);
    }

but in my case i won't Start the app, i will have to take over existing, running process.

Ideas?

Thanks in advance, Dan.

1

There are 1 answers

0
Alexander Petrov On BEST ANSWER

Try this:

foreach (var process in Process.GetProcesses())
{
    if (process.ProcessName == "notepad")
    // or
    //if (process.MainWindowTitle == "Untitled - Notepad")
    {
        SetParent(process.MainWindowHandle, panel1.Handle);
    }
};