如何使被调用的外部程序成为MDI窗口中的子窗口被管理?

tonyathome 2003-10-17 11:34:30
比如说,最大化(最小化)、主窗口退出时外部程序也相应地退出。???
...全文
32 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
tonyathome 2003-10-22
  • 打赏
  • 举报
回复
可是按照正常的mdi child窗口,当其最大化时子窗口的标题栏会显示在父窗口的标题栏中,如果按照采用以上方法,却无法做到。该如何解决呢?
Ringfo 2003-10-18
  • 打赏
  • 举报
回复
可以用API函数setParent A ,B 函数将A窗口放到B里面
再用GetwindowthreadProcess??得到该窗口的进程句柄
再用TerminateProcess函数结束进程,不过建议使用sendmessage发送关闭消息,给它一个保存工作成果的时间
rainstormmaster 2003-10-17
  • 打赏
  • 举报
回复
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As Long, ByVal lpWindowName As Long) As Long
Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Private Declare Function LockWindowUpdate Lib "user32" (ByVal hwndLock As Long) As Long
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Declare Function DestroyWindow Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
Private Declare Function Putfocus Lib "user32" Alias "SetFocus" (ByVal hwnd As Long) As Long
Const GW_HWNDNEXT = 2
Dim mWnd As Long
Function InstanceToWnd(ByVal target_pid As Long) As Long
Dim test_hwnd As Long, test_pid As Long, test_thread_id As Long
'Find the first window
test_hwnd = FindWindow(ByVal 0&, ByVal 0&)
Do While test_hwnd <> 0
'Check if the window isn't a child
If GetParent(test_hwnd) = 0 Then
'Get the window's thread
test_thread_id = GetWindowThreadProcessId(test_hwnd, test_pid)
If test_pid = target_pid Then
InstanceToWnd = test_hwnd
Exit Do
End If
End If
'retrieve the next window
test_hwnd = GetWindow(test_hwnd, GW_HWNDNEXT)
Loop
End Function
Private Sub Form_Load()
'KPD-Team 1999
'URL: http://www.allapi.net/
'E-Mail: KPDTeam@Allapi.net
Dim Pid As Long
'Lock the window update
LockWindowUpdate GetDesktopWindow
'Execute notepad.Exe
Pid = Shell("c:\windows\notepad.exe", vbNormalFocus)
If Pid = 0 Then MsgBox "Error starting the app"
'retrieve the handle of the window
mWnd = InstanceToWnd(Pid)
'Set the notepad's parent
SetParent mWnd, Me.hwnd
'Put the focus on notepad
Putfocus mWnd
'Unlock windowupdate
LockWindowUpdate False
End Sub
Private Sub Form_Unload(Cancel As Integer)
'Unload notepad
DestroyWindow mWnd
'End this program
TerminateProcess GetCurrentProcess, 0
End Sub
tonyathome 2003-10-17
  • 打赏
  • 举报
回复
虽然可以把它放入到MDI中去,可是管理的时候和真正的MdiChild窗口不一样啊。比如我关闭mdi时,却不能同时关闭外部的进程。还望赐教!

1,486

社区成员

发帖
与我相关
我的任务
社区描述
VB API
社区管理员
  • API
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧