Reputation: 4699
Is there any way run a jar (or any other process) file inside a panel in vb.net?
I am trying something like this:
Imports System.Diagnostics
Imports System.Runtime.InteropServices
Imports System.Threading
Public Class FGRUPOS
<DllImport("user32.dll")> Shared Function SetParent(ByVal hWndChild As IntPtr, ByVal hWndNewParent As IntPtr) As IntPtr
End Function
Private Sub FGRUPOS_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Dim p As Process
p = Process.Start("java.exe", "-jar processo.jar")
Threading.Thread.Sleep(500)
SetParent(p.MainWindowHandle, panel1.Handle)
End Sub
End Class
But it is not working.
Upvotes: 1
Views: 5727
Reputation: 4699
The code bellow (from vb.net Launch application inside a form) does the trick:
Public Class FGRUPOS
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
Friend Sub Rodar_Processo()
Dim p As System.Diagnostics.Process
p = Process.Start("notepad.exe")
p.WaitForInputIdle()
SetParent(p.MainWindowHandle, pnGrupo.Handle)
SendMessage(p.MainWindowHandle, WM_SYSCOMMAND, SC_MAXIMIZE, 0)
Me.BringToFront()
End Sub
End Class
Upvotes: 6