Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleStart another program inside your MDI form
KeywordsShell, start, execute, MDI, reparent, SetParent
CategoriesWindows
 
Use the Shell function to start the other application. Call the InstanceToWnd function to get the new program's Window handle (hWnd). Then use the SetParent API function to reparent the new window so it has the MDI program as its parent.

If you want to free the new window from the MDI form, use SetParent to restore its original parent.

 
Private Sub cmdRun_Click()
Dim pid As Long
Dim buf As String
Dim buf_len As Long
Dim styles As Long

    ' Start the program.
    pid = Shell(txtProgram.Text, vbNormalFocus)
    If pid = 0 Then
        MsgBox "Error starting program"
        Exit Sub
    End If

    ' Get the window handle.
    child_hwnd = InstanceToWnd(pid)

    ' Reparent the program so it lies inside
    ' the MDI form.
    old_parent = SetParent(child_hwnd, MDIForm1.hwnd)

    cmdRun.Enabled = False
    cmdFree.Enabled = True
End Sub

Private Sub cmdFree_Click()
    SetParent child_hwnd, old_parent

    cmdRun.Enabled = True
    cmdFree.Enabled = False
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated