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

blldw 2004-08-07 12:39:45
一个exe工程 ,有一个form窗体,叫form1,form1上有个按钮command1,还有一个picture box,目的是当作其他窗体的容器;新增加一个active dll工程,在这个工程中新增一个窗体form2。我想通过单击form1上的command1,来把form2加载到form1中的picture box中,应该怎么做呢?
...全文
324 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中!
内容概要:本文围绕基于两阶段鲁棒优化算法的微网多电源容量配置问题展开研究,针对微电网中风能、光伏、柴油发电机及储能系统等多元电源的容量规划难题,提出了一种能够有效应对源荷不确定性的优化方法。该方法采用两阶段鲁棒优化框架,第一阶段确定电源的最优配置容量,第二阶段通过调整运行策略应对不确定性扰动,从而提升系统在复杂环境下的适应性与经济性。文中结合Matlab实现了完整的算法建模与仿真验证,提供了清晰的代码实现路径,展示了模型在典型场景下的求解过程与结果分析,具有较强的工程应用价值。; 适合人群:具备一定电力系统基础知识和Matlab编程能力,从事新能源、微电网、优化调度等相关领域的科研人员及研究生。; 使用场景及目标:①解决含高比例可再生能源的微电网系统中电源容量配置的鲁棒性问题;②掌握两阶段鲁棒优化建模方法及其在能源系统中的实际应用;③为应对源荷不确定性提供可复现的技术方案与仿真工具支持; 阅读建议:此资源侧重于算法建模与实际仿真相结合,建议读者在理解鲁棒优化基本理论的基础上,结合Matlab代码逐模块分析,重点掌握不确定集构建、列与约束生成(C&CG)算法实现以及运行结果的经济性与可靠性评估方法,以实现从理论到实践的贯通。

7,789

社区成员

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

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