Private Declare Function SetParent Lib "user32" (ByVal hWndChild As IntPtr, ByVal hWndNewParent As IntPtr) As Integer
Private Declare Function LockWindowUpdate Lib "user32" (ByVal hwndLock As Integer) As Integer
Private Declare Function GetDesktopWindow Lib "user32" () As Integer
Private Declare Function Putfocus Lib "user32" Alias "SetFocus" (ByVal hwnd As IntPtr) As Integer
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim mdiContainer As MdiClient = Nothing
For Each ctl As Control In Me.Controls
If TypeOf ctl Is MdiClient Then
mdiContainer = DirectCast(ctl, MdiClient)
Exit For
End If
Next
'Lock the window update
LockWindowUpdate(GetDesktopWindow)
'Execute notepad.Exe
Dim myProcess As Process = Process.Start("notepad")
myProcess.WaitForInputIdle()
'Set the notepad's parent
SetParent(myProcess.MainWindowHandle, mdiContainer.Handle)
'Put the focus on notepad
Putfocus(myProcess.MainWindowHandle)
'Unlock windowupdate
LockWindowUpdate(0)
End Sub