samedi 9 mai 2015

Launching application inside form goes wrong

I have this code in my project

Declare Auto Function SetParent Lib "user32.dll" (ByVal hWndChild As IntPtr, ByVal hWndNewParent As IntPtr) As Integer
Declare Auto Function SendMessage Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
Private Const WM_SYSCOMMAND As Integer = 274
Private Const SC_MAXIMIZE As Integer = 61488
Dim proc As Process

Private Sub irI_Click(sender As Object, e As EventArgs) Handles irI.Click
    If b = True Then
        proc = Process.Start(Application.StartupPath & "\Resources\puzzle_temaI\bin\slidePuzzle.exe")
        proc.WaitForInputIdle()

        SetParent(proc.MainWindowHandle, Me.Panel1.Handle)
        SendMessage(proc.MainWindowHandle, WM_SYSCOMMAND, SC_MAXIMIZE, 0)
        b = False
    End If
End Sub

So, what i'm trying to do here is to open an application inside my panel1, and it works fine, the only problem is that 9/10 times i open it, it doesn't show inside the panel but somewhere else randomly.

I've run out of ideas and I'll appreciate any help.

Aucun commentaire:

Enregistrer un commentaire