RE: [Help] Embed exe to vb.net project 02-15-2014, 09:02 AM
#3
You can embed any other process by changing the ParentHandle from the process to something like picturebox1 (that is in your form).
imports:
incorporate user32.dll functions
notepad example: (the principle is the same for all GUIs)
imports:
Code:
Imports System.Diagnostics
Imports System.Text
Imports System.Runtime.InteropServices
Code:
Private Declare Function SetParent Lib "user32" (ByVal hwndChild As IntPtr, ByVal hwndNewParent As IntPtr) As Integer
Private Declare Function ShowWindow Lib "user32" (ByVal handle As IntPtr, ByVal nCmdShow As Integer) As Integer
notepad example: (the principle is the same for all GUIs)
Code:
Private Sub run_notepad()
Dim notepad As New Process
notepad.StartInfo.FileName = "notepad.exe"
notepad.Start()
Do Until notepad.WaitForInputIdle = True
Application.DoEvents()
Loop
embed("notepad")
End Sub
Private Sub embed(byval processname as string)
For Each p As Process In Process.GetProcesses()
If (p.ProcessName.Contains(processname)) Then
Dim handle As IntPtr = p.MainWindowHandle
SetParent(handle, PictureBox1.Handle)
ShowWindow(handle, 3) ' maximize the exe to dock it. (and remove borders)
End If
Next
End Sub