Re: Launch an application in an existing Form?

Daniel Barla-Szabo <[email protected]> Tue, 7 Aug 2007 13:09:37 +0200
Newsgroups gmane.comp.windows.devel.dotnet.winforms
Message-ID <[email protected]>
Yes, I saw that, the MSDN documentation is quite specific on that point.

The strange thing is that on the documentation from pinvoke.net
(http://pinvoke.net/default.aspx/user32/SetParent.html?diff=y) makes no
mention of this, and in their code sample actually launch notepad and
use SetParent on its main window.  There are probably certain cases
where this method isn't guaranteed to work, and Microsoft decided that a
simple "don't do it" is better than a lengthy explanation of where /
when you can use it (I think it's reasonable of them).


-----Original Message-----
From: Discussion forum for developers using Windows Forms to build apps
and controls [mailto:[email protected]] On Behalf Of
Peter Ritchie
Sent: 06 August 2007 09:22 PM
To: [email protected]
Subject: Re: [DOTNET-WINFORMS] Launch an application in an existing
Form?

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