BP Forums
Game Engine Import - Printable Version

+- BP Forums (https://bpforums.info)
+-- Forum: Archived Forums (https://bpforums.info/forumdisplay.php?fid=55)
+--- Forum: Archived Forums (https://bpforums.info/forumdisplay.php?fid=56)
+---- Forum: VB.NET (Visual Basic 2010/2008) (https://bpforums.info/forumdisplay.php?fid=8)
+---- Thread: Game Engine Import (/showthread.php?tid=788)



Game Engine Import - arrelin1 - 05-27-2013

I am trying to make a game making software run in a panel in my program. what happens now is that when my program starts, the game maker opens in its own window; I want it to open in my panel. Can someone tell me how to make it either run where it is in the panel and can have other buttons surrounding it or what I need to use to make it run INSIDE my program. I used the code

Code:
Private Sub Panel1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint
        System.Diagnostics.Process.Start("C:\Program Files (x86)\Unity\Editor\unity.exe")
    End Sub



Re: Game Engine Import - Snake_eyes - 05-29-2013

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.