Host/Embed Internet Explorer 8 application on Windows Forms Application

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
I need to host/embed an exe application on Windows Forms.<br/><br/>For example: A "Notepad.exe" should be launched and display it within a panel of Windows Forms.<br/><br/>The following code works perfectly fine for Notepad,Windows Media Player and other respective applications.<br/>Drag and drop a button and panel on Windows Form.<br/><br/>And use the  following code:<br/><br/><span style="font-size:x-small [<span style="color:#2b91af;font-size:x-small <span style="color:#2b91af;font-size:x-small DllImport<span style="font-size:x-small (<span style="color:#a31515;font-size:x-small <span style="color:#a31515;font-size:x-small "user32.dll"<span style="font-size:x-small , SetLastError = <span style="color:#0000ff;font-size:x-small <span style="color:#0000ff;font-size:x-small true<span style="font-size:x-small )]<font size=2>
 
</font>
<span style="color:#0000ff;font-size:x-small <span style="color:#0000ff;font-size:x-small private<span style="font-size:x-small <span style="color:#0000ff;font-size:x-small <span style="color:#0000ff;font-size:x-small static<span style="font-size:x-small <span style="color:#0000ff;font-size:x-small <span style="color:#0000ff;font-size:x-small extern<span style="font-size:x-small <span style="color:#0000ff;font-size:x-small <span style="color:#0000ff;font-size:x-small uint<span style="font-size:x-small SetParent(<span style="color:#2b91af;font-size:x-small <span style="color:#2b91af;font-size:x-small IntPtr<span style="font-size:x-small hWndChild, <span style="color:#2b91af;font-size:x-small <span style="color:#2b91af;font-size:x-small IntPtr<span style="font-size:x-small hWndNewParent);<font size=2>
[
</font>
<span style="color:#2b91af;font-size:x-small <span style="color:#2b91af;font-size:x-small DllImport<span style="font-size:x-small (<span style="color:#a31515;font-size:x-small <span style="color:#a31515;font-size:x-small "user32.dll"<span style="font-size:x-small , SetLastError = <span style="color:#0000ff;font-size:x-small <span style="color:#0000ff;font-size:x-small true<span style="font-size:x-small )]<font size=2>
 
</font>
<span style="color:#0000ff;font-size:x-small <span style="color:#0000ff;font-size:x-small private<span style="font-size:x-small <span style="color:#0000ff;font-size:x-small <span style="color:#0000ff;font-size:x-small static<span style="font-size:x-small <span style="color:#0000ff;font-size:x-small <span style="color:#0000ff;font-size:x-small extern<span style="font-size:x-small <span style="color:#0000ff;font-size:x-small <span style="color:#0000ff;font-size:x-small uint<span style="font-size:x-small SendMessage(<span style="color:#2b91af;font-size:x-small <span style="color:#2b91af;font-size:x-small IntPtr<span style="font-size:x-small hWnd, <span style="color:#0000ff;font-size:x-small <span style="color:#0000ff;font-size:x-small int<span style="font-size:x-small msg, <span style="color:#0000ff;font-size:x-small <span style="color:#0000ff;font-size:x-small int<span style="font-size:x-small wParam, <span style="color:#0000ff;font-size:x-small <span style="color:#0000ff;font-size:x-small int<span style="font-size:x-small lParam); <font size=2>
 
</font>
<span style="color:#0000ff;font-size:x-small <span style="color:#0000ff;font-size:x-small private<span style="font-size:x-small <span style="color:#0000ff;font-size:x-small <span style="color:#0000ff;font-size:x-small void<span style="font-size:x-small button1_Click(<span style="color:#0000ff;font-size:x-small <span style="color:#0000ff;font-size:x-small object<span style="font-size:x-small sender, <span style="color:#2b91af;font-size:x-small <span style="color:#2b91af;font-size:x-small EventArgs<span style="font-size:x-small e)
{
<font size=2>
    System.Diagnostics.
</font>
<span style="color:#2b91af;font-size:x-small <span style="color:#2b91af;font-size:x-small Process<span style="font-size:x-small p = System.Diagnostics.<span style="color:#2b91af;font-size:x-small <span style="color:#2b91af;font-size:x-small Process<span style="font-size:x-small .Start(<span style="color:#a31515;font-size:x-small <span style="color:#a31515;font-size:x-small @"C:\Program Files\Internet Explorer\iexplore.exe"<span style="font-size:x-small );<font size=2>
 
</font>
<span style="color:#008000;font-size:x-small <span style="color:#008000;font-size:x-small     //System.Diagnostics.Process p = System.Diagnostics.Process.Start(@"C:\Program Files\Windows Media Player\wmplayer.exe");
<span style="font-size:x-small <font size=2>
 
</font>
<span style="color:#008000;font-size:x-small <span style="color:#008000;font-size:x-small    //System.Diagnostics.Process p = System.Diagnostics.Process.Start("notepad.exe");
<span style="font-size:x-small
   p.WaitForInputIdle();
 
 
<font size=2>
   SetParent(p.MainWindowHandle,
</font>
<span style="color:#0000ff;font-size:x-small <span style="color:#0000ff;font-size:x-small this<span style="font-size:x-small .panel1.Handle);<br/>
   SendMessage(p.MainWindowHandle, 274, 61488, 0);
 
 
 
}
<font size=2>
 
</font>
<br/><br/>The internet explorer does not get embedded in the panel and launched seperately ,where as notepad,windows media player,calculator gets launched & gets embeded in the panel.<br/><br/><br/>What are the corrections needs to be done to the code so as to embed "Internet Explorer 8" within the panel? Or Please suggest any other code snippet which is better than this and achieve the requirements.<br/><br/>I know that "WebBrowser" control is available in Windows Forms but I want to embed "Internet Explorer 8". I have similar kind of applications which are launched seprately and does not get embedded in the panel. 

View the full article
 
Back
Top