Full code
Code:
'Declaring some constants to use with the SendMessage API
Private Const WM_SYSCOMMAND As Integer = 274
Private Const SC_MAXIMIZE As Integer = 61488
'This is the API that does all the hard work
<Runtime.InteropServices.DllImport("user32.dll")> _
Public Shared Function SetParent(ByVal hWndChild As IntPtr, ByVal hWndNewParent As IntPtr) As Integer
End Function
'This is the API used to maximize the window
<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
'This is the process that is currently set as a child to the form
Dim parentedProcess As Process
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
'This is important! If you have a child process on your form, it will terminate along with your form if you do not set its parent to Nothing
If Not parentedProcess Is Nothing Then
SetParent(parentedProcess.MainWindowHandle, Nothing)
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' SetProcessParent("RblxDev")
Dim myProcess As Process = New Process()
Dim hwndParent As Long
' Get notepad's window handle...
hwndParent = FindWindow(vbNullString, "Roblox - [Place1]")
Dim hwndButton As Long = FindWindowEx(hwndParent, IntPtr.Zero, "Place1", "")
' Place it inside the MDI form...
SetParent(hwndButton, Me.Handle)
End Sub
Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As IntPtr) As Long
Private Declare Auto Function FindWindow Lib "user32.dll" ( _
ByVal lpClassName As String, _
ByVal lpWindowName As String _
) As IntPtr
Private Declare Function FindWindowEx Lib "user32.dll" Alias "FindWindowExA" (ByVal hWndParent As IntPtr, ByVal hWndChildAfter As Integer, ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
Private Sub SetProcessParent(ByVal processName As String)
'Retrieve an array of running processes with the given name
Dim processes() As Process = Process.GetProcessesByName(processName)
If processes.Length = 0 Then
MessageBox.Show("No processes by that name found")
Else
'If there already is a process set as a child to our form, we set its parent to Nothing, to make it go back to its normal state.
If Not parentedProcess Is Nothing Then
SetParent(parentedProcess.MainWindowHandle, Nothing)
End If
'This forms new child will be the process on index 0 of the array
parentedProcess = processes(0)
SetParent(parentedProcess.MainWindowHandle, Me.Handle)
'SetParent(parentedprocess.MainWindowHandle,Me.Panel1.Handle) Try adding a panel to your form and use this line instead of the above line.
'Now lets maximize the window of the process
SendMessage(parentedProcess.MainWindowHandle, WM_SYSCOMMAND, SC_MAXIMIZE, 0)
End If
End Sub
Form1 Code
Code:
' SetProcessParent("RblxDev")
Dim myProcess As Process = New Process()
Dim hwndParent As Long
' Get notepad's window handle...
hwndParent = FindWindow(vbNullString, "Roblox - [Place1]")
Dim hwndButton As Long = FindWindowEx(hwndParent, IntPtr.Zero, "MDIClient", "")
hwndButton = FindWindowEx(hwndParent, hwndButton, "Place1", "")
SetParent(hwndButton, Me.Handle)
But it doesn't show anything in the form.