Re: Launch an application in an existing Form?
Peter Ritchie <[email protected]> Tue, 7 Aug 2007 07:38:56 -0400
| Newsgroups | gmane.comp.windows.devel.dotnet.winforms |
|---|---|
| Message-ID | <LISTSERV%[email protected]> |
PInvoke.net is not Microsoft documentation; it's more like a wiki--so its content is whatever someone wants to put up there, right or wrong. SetParent is probably like cross-thread window communication in Windows; it doesn't check and assumes you're following the "rules". I would suspect there's some very distinct things that will cause problems with using SetParent, things you can't overcome. If you're lucky you'll find them early; if you're not, a customer will find them and you'll realize there really is no way to reliably embed an application in the window of another. On Tue, 7 Aug 2007 13:09:37 +0200, Daniel Barla-Szabo <[email protected]> wrote: >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