我要实现这样一个功能,应该如何实现啊?

blldw 2004-08-07 12:39:45
一个exe工程 ,有一个form窗体,叫form1,form1上有个按钮command1,还有一个picture box,目的是当作其他窗体的容器;新增加一个active dll工程,在这个工程中新增一个窗体form2。我想通过单击form1上的command1,来把form2加载到form1中的picture box中,应该怎么做呢?
...全文
266 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
starsoulxp 2004-08-11
  • 打赏
  • 举报
回复
使用setparent
smile8088 2004-08-08
  • 打赏
  • 举报
回复
学习,关注......
cso 2004-08-07
  • 打赏
  • 举报
回复
利用SetParent
Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long

比如要把form2放到form1的picture1中(form1已经显示):


load form2
SetParent form2.hwnd,form1.picture1.hwnd

即可
cso 2004-08-07
  • 打赏
  • 举报
回复
主要利用SetParent 实现:

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
blldw 2004-08-07
  • 打赏
  • 举报
回复
up!
blldw 2004-08-07
  • 打赏
  • 举报
回复
我是这样做的: 在active dll工程中获得exe中的form1句柄,然后使用dll工程中的showForm方法来把form2放入到form1中的picture box中,但是最大的问题是我竟然不能编辑form2中的文本框,就是不能输入东西!!! 为什么啊,我怎么才能在exe中获得dll中的form2句柄? dll中实现这样的一个方法不行:
Public Sub showReg(frm As Form)
'codes
End Sub

错误是:private object modules cannot be used in public object modules as parameters or return types for public procedures, ...
cso 2004-08-07
  • 打赏
  • 举报
回复
那么没有什么关系的,只要你获得active dll工程的form句柄,就可以了,至于句柄如何获得,如果是别人的dll.你可以等到他的form出来后马上获得并且隐藏,至于是你的那就更好办了,直接提供一个接口就可以.
反正你要把一个form放入到exe工程中的form1的picturebox中,是肯定会用到SetParent 的
blldw 2004-08-07
  • 打赏
  • 举报
回复
to: cso
我想你误会我的意思了,我不是把外部程序比如notepad.exe放入我的form1中的picturebox容器中,而是要把一个active dll工程的一个form放入到exe工程中的form1的picturebox中!

7,763

社区成员

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

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