How to place an exe in the Vb.net form

Asked

Viewed 324 times

-2

Well, I have the code

Dim proc As Process
proc = Process.Start("notepad.exe")
proc.WaitForInputIdle()
' Set the panel control as the application's parent
SetParent(proc.MainWindowHandle, Me.BetaBox.Handle)
'Maximize application
SendMessage(proc.MainWindowHandle, 274, 61488, 0)

It performs well, but I wanted it to put itself inside the form even opening directly, is there any way? Need to while something like?

  • In short, you want to put the main window (Form) of the process within its own Form? If so, the answer is is not possible. Unless you try to emulate the executable within a container implemented with virtualization, but that would take a lot of work. It’s very complicated.

  • it is possible I have seen a program using the same, when opening the program by clicking on the atalha, or directly in the exe the program recognizes the Process ID and sends to the form, thus emulating inside the form, without taking space in the explorer’s shortcut bar

  • Yes, there is an application container, you would have to implement a.

  • yes, I would like to know how it is :P do not have the basis of how to make only this code above works I use this way, I will update

1 answer

0

   <DllImport("user32.dll")> Public Shared Function SetParent(ByVal hwndChild As IntPtr, ByVal hwndNewParent As IntPtr) As Integer
    End Function
    Const WM_NCLBUTTONDOWN As Integer = &HA1
    Const WM_LBUTTONDOWN As Integer = &H201
    Const HTCAPTION As Long = 2
    Private Declare Function ReleaseCapture Lib "user32" () As Long
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, lParam As Integer) As Long
    Protected Overrides Sub WndProc(ByRef m As Message)
        MyBase.WndProc(m)
        If m.Msg = WM_LBUTTONDOWN Then
            ReleaseCapture()
            SendMessage(Me.Handle, WM_NCLBUTTONDOWN, HTCAPTION, &H0)
        End If
    End Sub

Private Sub Soul_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Soul.Click

                Dim proc As Process
                proc = Process.Start("notepad.exe")
                proc.WaitForInputIdle()
                ' Set the panel control as the application's parent
                SetParent(proc.MainWindowHandle, Me.CommandLog.Handle)
                ' Maximize application
                SendMessage(proc.MainWindowHandle, 274, 61488, 0)
        End Sub

this code works by clicking the button, but I wanted it to recognize the application as soon as the application opens, without needing button etc.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.