|
|
Title | Start another program inside a PictureBox |
Keywords | Shell, start, execute, 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 PictuerBox 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
' 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 PictureBox.
old_parent = SetParent(child_hwnd, picChild.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
|
|
|
|
|
|