DLL动态窗体问题

Dision LI 2010-10-07 11:09:35
系统分模块设计DLL...

'这里是动态弹出工程里的窗体
On Error GoTo Err_CommandBars_Execute
Dim frm As Form
Set frm = Forms.Add("这里是动态名字,比如frmLogin")
frm.Left = (MDIFrmMain.ScaleWidth - frm.Width) / 2
frm.Top = (MDIFrmMain.ScaleHeight - frm.Height) / 2
frm.Show
Set frm = Nothing
Exit_CommandBars_Execute:
Exit Sub
Err_CommandBars_Execute:
Exit Sub
Resume Exit_CommandBars_Execute



'---DLL CoffeeMonitor
Option Explicit
Public Enum cfeModality
cfeModal = vbModal
cfeModeless = vbModeless
End Enum

Public Sub ShowForm(Optional Modality As _
cfeModality = cfeModal)
Dim frm As New TestForm
If Modality = cfeModeless Then
frm.Caption = "TestForm-Modeless"
Else
frm.Caption = "TestForm-Modeless"
End If
frm.Show Modality
End Sub

'--窗体
Option Explicit
Private mcmnTest As CoffeeMonitor

Private Sub Form_Load()
Set mcmnTest = New CoffeeMonitor
End Sub

Private Sub cmdModal_Click()
mcmnTest.ShowForm cfeModal
End Sub

Private Sub cmdModeless_Click()
mcmnTest.ShowForm cfeModeless
End Sub


现在转换成DLL的该如何简便地实现?
主EXE里有个MDIMainFrom 怎么动态打开每个DLL里的窗体,怎么做
...全文
119 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
Dision LI 2010-10-13
  • 打赏
  • 举报
回复

'Business DLL里写的类模块 clsShowFrom
Option Explicit
Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Public Function Show(FrmName As String) As Object
On Error Resume Next

Dim frm As Form
Set frm = Forms.Add(FrmName)
Load FrmBusiness

SetParent FrmBusiness.hWnd, FindWindowEx(FindWindow(vbNullString, "MDIFormWJ"), 0, "MDIClient", "")
Debug.Print FindWindowEx(FindWindow(vbNullString, "MDIFormWJ"), 0, "MDIClicent", "")
Debug.Print FindWindow(vbNullString, "MDIFormWJ")
Set Show = FrmBusiness
FrmBusiness.Show
End Function




'另外一工程引用Business DLL,新建MDI窗体 MDIFormWJ
Private Sub 测试2_Click()
'传递的DLL名、类名、窗体名--三个信息保存在某菜单表中
Dim obj As Object
Set obj = CreateObject("Business.clsShowFrom")
obj.Show ("FrmBusiness")
' Dim c As New clsShowFrom
' c.Show ("FrmBusiness")
End Sub


这里是根据MDIFormWJ窗体名做查找,动态设置窗体名则可在DLL里动态设置.

解决。
孤独剑_LPZ 2010-10-07
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 roock 的回复:]
应该使用ActiveX EXE吧,这个可以有窗口.
[/Quote]
恩,不错
Roock 2010-10-07
  • 打赏
  • 举报
回复
应该使用ActiveX EXE吧,这个可以有窗口.
lsh6688 2010-10-07
  • 打赏
  • 举报
回复
dll不是一个动态库吗
怎么会有窗体
你把它们设计到一个控件里 然后运用这个空间吧
不知道我说的对吗

7,759

社区成员

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

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