VB中如何判断窗体是否已加载
展开全部
方法1:调用API函数FindWindow,通过窗体的Caption属性判断
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function IsWindow Lib "user32" (ByVal hwnd As Long) As Long
Dim lngAns As Long
lngAns = FindWindow(vbNullString, "要查找窗体的CAPTION")
lngAns = IsWindow(lngAns)
If lngAns < 0 Then
MsgBox "窗体已经被加载!", vbOKOnlyEndElseMsgBox "窗体未被加载!", vbOKOnlyEnd If方法2:访问Forms集合,也是通过Caption判断
'在Forms集合中进行遍历
For Each frmEach In Forms
If frmEach Is frmTest Then '这样判断也可以
blnResult = TrueExit ForEnd If方法3:访问Forms集合,通过name判断
Private Function IsLoad(ByVal frmTest As Form) As Boolean
Dim frmEach As Form
Dim blnResult As Boolean
blnResult = False
'在Forms集合中进行遍历
For Each frmEach In Forms
If frmEach.Name = frmTest.Name Then
blnResult = TrueExit ForEnd IfNext
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询