有没有办法在vb.net的面板中运行jar(或任何其他进程)文件?
我正在尝试这样的事情:
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
但它没有用。
答案 0 :(得分:6)
下面的代码(来自vb.net Launch application inside a form)可以解决问题:
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