Public Declare Function SetParent Lib "USER32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
Function InstanceToWnd(ByVal target_pid As Long) As Long
Dim test_hwnd As Long
Dim test_pid As Long
Dim test_thread_id As Long
' Get the first window handle.
test_hwnd = FindWindow(ByVal 0&, ByVal 0&)
' Loop until we find the target or we run out
' of windows.
Do While test_hwnd <> 0
' See if this window has a parent. If not,
' it is a top-level window.
If GetParent(test_hwnd) = 0 Then
' This is a top-level window. See if
' it has the target instance handle.
test_thread_id = GetWindowThreadProcessId(test_hwnd, test_pid)
If test_pid = target_pid Then
' This is the target.
InstanceToWnd = test_hwnd
Exit Do
End If
End If
' Examine the next window.
test_hwnd = GetWindow(test_hwnd, GW_HWNDNEXT)
Loop
End Function
Sub RunSubExe(hwnd As Long, FileName As String)
Dim Exe_Hwnd As Long
Dim Exe_OldParent As Long
Dim pid As Long
Dim buf As String
Dim buf_len As Long
Dim styles As Long
On Error Resume Next
pid = Shell(FileName, vbNormalFocus)
If pid = 0 Then
MsgBox "打开程序错误!", vbExclamation, "提示"
Exit Sub
End If
Exe_Hwnd = InstanceToWnd(pid)
Exe_OldParent = SetParent(Exe_Hwnd, hwnd)
End Sub