我要把3DSMax加到我的MDIForm中来:
pid = Shell(strAppCmd, vbNormalFocus)
If pid = 0 Then
Exit Sub
End IfmWnd = OpenProcess(SYNCHRONIZE, 0, pid)
Card_OldParent& = SetParent(mWnd, Me.hwnd)开机第一次运行肯定失败,以后有一定的失败几率,如果经常运行,就没有问题了(好像是刚开机3DSMax第一次运行,资源还没有加载,所以失败了)
但我跟踪了SetParent函数的返回值,有两种可能:6553?和3DS的hwnd,但两种返回值又和是否成功执行没有关系,我已经试验了好多方法,比如WaitForSingleObj等,但都不能解决,只好求助大家
(注:strAppCmd就是3ds的路径文件名,如果换成记事本等小程序,就没有任何问题)
pid = Shell(strAppCmd, vbNormalFocus)
If pid = 0 Then
Exit Sub
End IfmWnd = OpenProcess(SYNCHRONIZE, 0, pid)
Card_OldParent& = SetParent(mWnd, Me.hwnd)开机第一次运行肯定失败,以后有一定的失败几率,如果经常运行,就没有问题了(好像是刚开机3DSMax第一次运行,资源还没有加载,所以失败了)
但我跟踪了SetParent函数的返回值,有两种可能:6553?和3DS的hwnd,但两种返回值又和是否成功执行没有关系,我已经试验了好多方法,比如WaitForSingleObj等,但都不能解决,只好求助大家
(注:strAppCmd就是3ds的路径文件名,如果换成记事本等小程序,就没有任何问题)
再Findwindow就可以准确的找到程序的句柄了!:p
----------------------------------
夜已深,还有什么人,像我这样,醒着在编程海纳百川,有容乃大;
壁立千仞,无欲则刚。
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我这样找在刚开机后第一次执行还是不行
If pid = 0 Then
Exit Sub
End IfmWnd = OpenProcess(SYNCHRONIZE, 0, pid)
Card_OldParent& = SetParent(mWnd, Me.hwnd)-------------------------------------------什么?OpenProcess 返回的是窗口句柄?
用 WaitForInputIdle API函数。而且,强烈建议用 CreateProcess 函数!