EDN Admin
Well-known member
I pieced together this code from various sources. It embeds an external application into a panel on the form. For some reason the top 3/4 inch or so of the form becomes white and any controls in that area appear very dirty, basically cant use that area
of the form for anything. Does anybody know how to resolve this problem?
The following code launches an instance of Internet Explorer and then embeds it in the panel. The panel is anchored top, bottom, left and right in order to resize the panel when the form resizes.
See pictures below the code to see the before and after effect of embedding Internet Explorer in the panel with regard to the top 3/4 of the form becoming basically unuseable.
On another note this does not happen when I embed Notepad in the panel.
<pre class="prettyprint lang-vb Imports System.Runtime.InteropServices
Public Class Form1
Private Const WM_SYSCOMMAND As Integer = &H112
Private Const SC_MINIMIZE As Integer = &HF020
Private Const SC_MAXIMIZE As Integer = &HF030
<Runtime.InteropServices.DllImport("user32.dll")> _
Public Shared Function SetParent(ByVal hWndChild As IntPtr, ByVal hWndNewParent As IntPtr) As Integer
End Function
<Runtime.InteropServices.DllImport("user32.dll")> _
Public Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
End Function
Dim parentedProcess As Process
Dim InternetExplorer As Integer = 0
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub Form1_Resize(sender As Object, e As EventArgs) Handles Me.Resize
If Not parentedProcess Is Nothing Then
SendMessage(parentedProcess.MainWindowHandle, WM_SYSCOMMAND, SC_MINIMIZE, 0)
SendMessage(parentedProcess.MainWindowHandle, WM_SYSCOMMAND, SC_MAXIMIZE, 0)
Else
End If
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
InternetExplorer = Process.Start("iexplore").Id
System.Threading.Thread.Sleep(2000)
Me.Text = InternetExplorer.ToString Displays the process ID for testing purposes, you can remove this if you desire.
Dim IEID As Process = Process.GetProcessById(InternetExplorer)
If IEID.Id = Nothing Then
MessageBox.Show("No processesby that name found")
Else
If Not parentedProcess Is Nothing Then
SetParent(parentedProcess.MainWindowHandle, Nothing)
End If
parentedProcess = IEID
SetParent(parentedProcess.MainWindowHandle, Panel1.Handle)
SendMessage(parentedProcess.MainWindowHandle, WM_SYSCOMMAND, SC_MAXIMIZE, 0)
End If
End Sub
Private Sub Panel1_Paint(sender As Object, e As PaintEventArgs) Handles Panel1.Paint
End Sub
End Class[/code]
<br/>
<img alt="" src="http://social.msdn.microsoft.com/Forums/getfile/213771
<
Youve taught me everything I know but not everything you know.
<br/>
View the full article
of the form for anything. Does anybody know how to resolve this problem?
The following code launches an instance of Internet Explorer and then embeds it in the panel. The panel is anchored top, bottom, left and right in order to resize the panel when the form resizes.
See pictures below the code to see the before and after effect of embedding Internet Explorer in the panel with regard to the top 3/4 of the form becoming basically unuseable.
On another note this does not happen when I embed Notepad in the panel.
<pre class="prettyprint lang-vb Imports System.Runtime.InteropServices
Public Class Form1
Private Const WM_SYSCOMMAND As Integer = &H112
Private Const SC_MINIMIZE As Integer = &HF020
Private Const SC_MAXIMIZE As Integer = &HF030
<Runtime.InteropServices.DllImport("user32.dll")> _
Public Shared Function SetParent(ByVal hWndChild As IntPtr, ByVal hWndNewParent As IntPtr) As Integer
End Function
<Runtime.InteropServices.DllImport("user32.dll")> _
Public Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
End Function
Dim parentedProcess As Process
Dim InternetExplorer As Integer = 0
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub Form1_Resize(sender As Object, e As EventArgs) Handles Me.Resize
If Not parentedProcess Is Nothing Then
SendMessage(parentedProcess.MainWindowHandle, WM_SYSCOMMAND, SC_MINIMIZE, 0)
SendMessage(parentedProcess.MainWindowHandle, WM_SYSCOMMAND, SC_MAXIMIZE, 0)
Else
End If
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
InternetExplorer = Process.Start("iexplore").Id
System.Threading.Thread.Sleep(2000)
Me.Text = InternetExplorer.ToString Displays the process ID for testing purposes, you can remove this if you desire.
Dim IEID As Process = Process.GetProcessById(InternetExplorer)
If IEID.Id = Nothing Then
MessageBox.Show("No processesby that name found")
Else
If Not parentedProcess Is Nothing Then
SetParent(parentedProcess.MainWindowHandle, Nothing)
End If
parentedProcess = IEID
SetParent(parentedProcess.MainWindowHandle, Panel1.Handle)
SendMessage(parentedProcess.MainWindowHandle, WM_SYSCOMMAND, SC_MAXIMIZE, 0)
End If
End Sub
Private Sub Panel1_Paint(sender As Object, e As PaintEventArgs) Handles Panel1.Paint
End Sub
End Class[/code]
<br/>
<img alt="" src="http://social.msdn.microsoft.com/Forums/getfile/213771
<
Youve taught me everything I know but not everything you know.
<br/>
View the full article