This is a simple technique on how to add an external application on your MDI form as a child. First you have to have MDI form, a button to trigger the event and a panel which will host the embedded application. You have to import first the references.
#VB.NET
Imports System
Imports System.IO
Imports System.Text
Imports System.Diagnostics
Imports System.Drawing
Imports System.Data
Imports System.Windows
Imports System.Windows.Forms
Imports System.Runtime.InteropServices
Imports System.Threading
#CSharp
Using System;
Using System.IO;
Using System.Text;
Using System.Diagnostics;
Using System.Drawing;
Using System.Data;
Using System.Windows;
Using System.Windows.Forms;
Using System.Runtime.InteropServices;
Using System.Threading;
Then after that, you have to declare the necessary functions.
<DllImport("User32", CharSet:=CharSet.Auto, ExactSpelling:=True, SetLastError:=False)>
Public Shared Function SetParent(ByVal hWndChild As IntPtr, ByVal hWndParent As IntPtr) As IntPtr
End Function
Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
Public Shared Function SendMessage(ByVal hWndChild As IntPtr, ByVal Msg As Int32, ByVal wParam As Int32, ByVal lParam As Int32) As IntPtr
End Function
The main code for the triggered event is this:
#VB.NET Dim proc As Process
proc = Process.Start("notepad.exe") ' or this proc = Process.Start("winword.exe")
'proc.StartInfo.WindowStyle = ProcessWindowStyle.Normal
proc.WaitForInputIdle()
Thread.Sleep(1000)
SetParent(proc.MainWindowHandle, Me.Panel1.Handle)
SendMessage(proc.MainWindowHandle, 274, 61488, 0)
proc.WaitForExit()
#CSharp
Process proc
proc = Process.Start("notepad.exe"); ' or this proc = Process.Start("winword.exe");
'proc.StartInfo.WindowStyle = ProcessWindowStyle.Normal();
proc.WaitForInputIdle();
Thread.Sleep(1000);
SetParent(proc.MainWindowHandle, Me.Panel1.Handle);
SendMessage(proc.MainWindowHandle, 274, 61488, 0);
proc.WaitForExit();
Hope you find it helpful. Dont forget to like, comment and share. Happy coding. Cheers! :D