ousoonerjoe
Programmer
I've been looking all over this site and Google for a practical way to pull external applications inside the MDI form. For example, running Calculator and/or Notepad inside the main MDI form of my project. When I use the code I found (shown below), it does pull the application inside the MDI, but it is on top of the menus and status bars. Is there a way to pull an external application in and have it "follow the rules"?
NOTE: Looking for VB.net 2005. There are several samples for VB6.
I also found a reference to Assembly.LoadFrom(). When trying to use it, I continually encounter "Could not load file or assembly 'file:///C:\WINDOWS\System32\calc.exe' or one of its dependencies. The module was expected to contain an assembly manifest."
Any tips, thoughts, or suggestions you have are welcomed. Thank you.
"...and did we give up when the Germans bombed Pearl Harbor? NO!"
"Don't stop him. He's roll'n.
NOTE: Looking for VB.net 2005. There are several samples for VB6.
Code:
Private hCalc As IntPtr
Private hParent As IntPtr
Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, _
ByVal lpWindowName As String) As IntPtr
Private Declare Function SetParent Lib "user32.dll" (ByVal hWndChild As IntPtr, _
ByVal hWndNewParent As IntPtr) As IntPtr
Private Sub frmMain_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
hCalc = FindWindow(vbNullString, "Calculator")
If hCalc.ToInt32 <> 0 Then
hParent = SetParent(hCalc, Me.Handle)
End If
End Sub
Private Sub frmMain_Closed(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Closed
If hCalc.ToInt32 <> 0 Then
SetParent(hCalc, hParent)
End If
End Sub
I also found a reference to Assembly.LoadFrom(). When trying to use it, I continually encounter "Could not load file or assembly 'file:///C:\WINDOWS\System32\calc.exe' or one of its dependencies. The module was expected to contain an assembly manifest."
Code:
Private Sub mnuCalculator_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuCalculator.Click
Dim AssemblyFile As String
Dim Resp As Assembly
AssemblyFile = My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "SystemRoot", "")
AssemblyFile = AssemblyFile & "\System32\calc.exe"
Resp = Assembly.LoadFrom(AssemblyFile)
End Sub
Any tips, thoughts, or suggestions you have are welcomed. Thank you.
"...and did we give up when the Germans bombed Pearl Harbor? NO!"
"Don't stop him. He's roll'n.