Public
Class Form1Declare Function ShowWindow Lib "user32" (ByVal hWnd As System.IntPtr, ByVal nCmdShow As Integer) As Boolean
Declare Function SetParent Lib "user32" (ByVal hWndChild As System.IntPtr, ByVal hWndNewParent As System.IntPtr) As System.IntPtr
Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As System.IntPtr) As Integer
Declare Function SetWindowPos Lib "user32" (ByVal hWnd As Integer, ByVal hWndInsertAfter As Integer, ByVal X As Integer, ByVal Y As Integer, ByVal cx As Integer, ByVal cy As Integer, ByVal uFlags As Integer) As Boolean
Dim _Mdi As MdiClient
Dim _MdiClientHandle As Integer
Dim _Processes As Collection = New Collection()
Private Sub DocMgrToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DocMgrToolStripMenuItem.Click
Dim AppPath As String = "c:\MyVfpApp\"
Dim App2Run As String = "TheBestVfpAppEver.exe"
If Not _Processes.Contains(App2Run) Then
Dim loStart As New System.Diagnostics.ProcessStartInfo(AppPath + App2Run)
loStart.WorkingDirectory = AppPath
Dim oProcess As System.Diagnostics.Process = System.Diagnostics.Process.Start(loStart)
System.Threading.Thread.Sleep(5000)
_MdiClientHandle = oProcess.MainWindowHandle.ToInt32()
SetParent(_MdiClientHandle, _Mdi.Handle)
SetWindowPos(_MdiClientHandle, 0, 0, 0, _Mdi.Width, _Mdi.Height, &H20)
_Processes.Add(oProcess, App2Run)
Else
MsgBox(App2Run + " is already open.")
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
_Mdi = New MdiClient()
_Mdi.BackColor = System.Drawing.Color.White
Me.IsMdiContainer = True
Me.Controls.Add(_Mdi)
End Sub
Private Sub Form1_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
For Each oProcess As System.Diagnostics.Process In _Processes
If Not oProcess.HasExited Then
oProcess.Kill()
End If
Next
End Sub
Private Sub Form1_SizeChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.SizeChanged
If _MdiClientHandle > 0 Then
SetWindowPos(_MdiClientHandle, 0, 0, 0, _Mdi.Width, _Mdi.Height, &H20)
End If
End Sub
End Class