05-29-2013, 03:02 AM
In order to open an extarnal program you need to get it's handle and change it and to do that you need to use 2 functions SetParent and ShowWindow , and 1 const SW_MAXIMIZE
[code2=vbnet]Declare 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
Private Const SW_MAXIMIZE As Integer = 3[/code2]
Now you used Panel1.Paint event witch is the worst event to use because everytime the panel is redrawwn it will open the program again and again . I sugest using either a button or the form load event. Here is the code to open the program in your pannel
[code2=vbnet]Dim pinfo As New ProcessStartInfo("C:\Program Files (x86)\Unity\Editor\unity.exe")
Dim p As Process = System.Diagnostics.Process.Start(pinfo)
System.Threading.Thread.Sleep(50)
SetParent(p.MainWindowHandle, Me.Panel1.Handle)
ShowWindow(p.MainWindowHandle, SW_MAXIMIZE)[/code2]
The code above should do the trick.
[code2=vbnet]Declare 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
Private Const SW_MAXIMIZE As Integer = 3[/code2]
Now you used Panel1.Paint event witch is the worst event to use because everytime the panel is redrawwn it will open the program again and again . I sugest using either a button or the form load event. Here is the code to open the program in your pannel
[code2=vbnet]Dim pinfo As New ProcessStartInfo("C:\Program Files (x86)\Unity\Editor\unity.exe")
Dim p As Process = System.Diagnostics.Process.Start(pinfo)
System.Threading.Thread.Sleep(50)
SetParent(p.MainWindowHandle, Me.Panel1.Handle)
ShowWindow(p.MainWindowHandle, SW_MAXIMIZE)[/code2]
The code above should do the trick.
Sssssssssoftware developer...