|
|
Title | Start another program inside your MDI form |
Keywords | Shell, start, execute, MDI, reparent, SetParent |
Categories | Windows |
|
|
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
|
|
|
|
|
|