<DllImport("user32.dll")> Public Shared Function SetParent(ByVal hwndChild As IntPtr, ByVal hwndNewParent As IntPtr) As Integer
End Function
Const WM_NCLBUTTONDOWN As Integer = &HA1
Const WM_LBUTTONDOWN As Integer = &H201
Const HTCAPTION As Long = 2
Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, lParam As Integer) As Long
Protected Overrides Sub WndProc(ByRef m As Message)
MyBase.WndProc(m)
If m.Msg = WM_LBUTTONDOWN Then
ReleaseCapture()
SendMessage(Me.Handle, WM_NCLBUTTONDOWN, HTCAPTION, &H0)
End If
End Sub
Private Sub Soul_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Soul.Click
Dim proc As Process
proc = Process.Start("notepad.exe")
proc.WaitForInputIdle()
' Set the panel control as the application's parent
SetParent(proc.MainWindowHandle, Me.CommandLog.Handle)
' Maximize application
SendMessage(proc.MainWindowHandle, 274, 61488, 0)
End Sub
This code works by clicking the button, but I wanted it to recognize the application as soon as the application opened, without needing a button etc.