在VB.NET中运行面板内的进程

时间:2014-06-27 13:00:18

标签: vb.net

有没有办法在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

但它没有用。

1 个答案:

答案 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