好久没来了 有个问题请教

fu0212 2006-05-26 12:41:12
在从前看过一段代码 可以实现 让其他程序界面 窗体 运行于自己做的这个程序的一个PICTURE控件中

那位大侠知道啊 谢谢了
...全文
174 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
fu0212 2006-06-07
  • 打赏
  • 举报
回复
哈哈 是我信誉有些低 可那是我提出有些问题没有回答啊 没办法只有删贴了啊
ZOU_SEAFARER 2006-05-26
  • 打赏
  • 举报
回复
来晚了!!
benyfeifei 2006-05-26
  • 打赏
  • 举报
回复
楼上的思路正确,具体代码如下:

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
verywzm 2006-05-26
  • 打赏
  • 举报
回复
先用findwindow之类的函数找到该窗口句柄,在用SetParent函数设置它的新父窗口句柄为图片框句柄。

【操作系统】
Win9X:Yes
WinNT:Yes
【说明】
指定一个窗口的新父(在vb里使用:利用这个函数,vb可以多种形式支持子窗口。例如,可将控件从一个容器移至窗体中的另一个。用这个函数在窗体间移动控件是相当冒险的,但却不失为一个有效的办法。如真的这样做,请在关闭任何一个窗体之前,注意用SetParent将控件的父设回原来的那个)
【返回值】
Long,前一个父窗口的句柄
【其它】
可用这个函数在运行期将vb控件置入容器控件内部(比如将一个按钮设成图象或窗体控件的子窗口),或者将控件从一个容器控件移至另一个。控件移至另一个父后,它的位置将由新父的坐标系统决定。这样一来,有必要重新规定控件的位置,使其能在目标位置显示出来
【参数表】
hWndChild ------ Long,子窗口的句柄
hWndNewParent -- Long,hWndChild的新父
jadeluo 2006-05-26
  • 打赏
  • 举报
回复
ZOU_SEAFARER(国际海员) ( ) 信誉:100 2006-05-26 09:35:00 得分: 0


来晚了!!


别嫌晚。看看LZ的信誉分,估计你来再早也没戏。
michael_zy 2006-05-26
  • 打赏
  • 举报
回复
但是一点作用都没有的代码。。。。把别的程序加到你的picture后,如果把那个程序最小化,就看不到了,也还原不了。这早就做过,一点实用价值都没有
老之 2006-05-26
  • 打赏
  • 举报
回复
SetParent

1,486

社区成员

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

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