Re: Launch an application in an existing Form?
Peter Ritchie <[email protected]> Mon, 6 Aug 2007 15:21:39 -0400
| Newsgroups | gmane.comp.windows.devel.dotnet.winforms |
|---|---|
| Message-ID | <LISTSERV%[email protected]> |
The documentation for SetParent does point out that "The new parent window and the child window must belong to the same application." So, while it might appear to work, it's certainly not supported. On Mon, 6 Aug 2007 11:18:40 +0200, Daniel Barla-Szabo <[email protected]> wrote: >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