Re: Launch an application in an existing Form?

Daniel Barla-Szabo <[email protected]> Mon, 6 Aug 2007 11:18:40 +0200
Newsgroups gmane.comp.windows.devel.dotnet.winforms
Message-ID <[email protected]>
Hi,

Yes, it's possible... It's not often done so it's quite tricky to find
documentation on it.  Here's an example:


// at the top, import these:

using System.Diagnostics;
using System.Runtime.InteropServices;


// and here's an example dummy form that launches notepad and "docks" it
inside your form:
// just attach the button1_Click code to a button's click event.

    public partial class Form1 : Form
    {
        [DllImport("user32.dll")]
        static extern IntPtr SetParent(IntPtr hWndChild, IntPtr
hWndNewParent);
        
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            ProcessStartInfo info = new ProcessStartInfo("notepad.exe");

            Process notepadProcess = Process.Start(info);

            notepadProcess.WaitForInputIdle();

            SetParent(notepadProcess.MainWindowHandle, this.Handle);
        }
    }



Here's another example:

http://www.codeproject.com/cs/miscctrl/AppControl.asp

Regards,

Daniel.




-----Original Message-----
From: Discussion forum for developers using Windows Forms to build apps
and controls [mailto:[email protected]] On Behalf Of
Paul ten Brink
Sent: 06 August 2007 10:42 AM
To: [email protected]
Subject: [DOTNET-WINFORMS] Launch an application in an existing Form?

Hi,

I am sending this question on behalf of my son (age 17) who is writing
his
first .Net program using C# 2.0.

The program is a kind of framework that lets you define, position, and
size
windows that contain 'appliances'. One appliance can be a website,
another
an instant messenger program, yet another a game.

The question is: is it possible to launch an application to run in an
existing WinForms window (Form)? Or maybe launch an application and
after
it's loaded set its 'Parent' property? The last option will require some
low level GDI32 or Kernel32 hacking, I guess.

Thanks in advance,
Paul ten Brink
[email protected]