Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open External Application in MDI Form

Status
Not open for further replies.

ousoonerjoe

Programmer
Jun 12, 2007
925
US
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.
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.
 
I would also like to pull a Console Window into the MDI, but haven't found anything new to aid with this overall task.

Any thoughts or suggestions are welcome.

"...and did we give up when the Germans bombed Pearl Harbor? NO!"
"Don't stop him. He's roll'n.
 
UPDATE: The following apparently only works with other .Net applications.
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

The Windows Calculator is not a .Net Application. Any insight on how to make an external application bind to an MDI form and not be on top of the status and menu bars would be highly appreciated.

--------------------------------------------------
"...and did we give up when the Germans bombed Pearl Harbor? NO!"

"Don't stop him. He's roll'n."
--------------------------------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top