调用API 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 "窗体已经被加载!", vbOKOnly End Else MsgBox "窗体未被加载!", vbOKOnly End If
if form1 is nothing then MsgBox "Form未加载" else MsgBox "Form已加载" end if建议不要用KillerAPP的那种方法,因为不同窗体会有相同CAPTION的.尤其是在WINDOWS中.
Sorry, 刚才的方法的确不行!以下方法完全可以,仅供参考(枚举) Dim frm As Object Dim blnFlag As Boolean For Each frm In Forms If frm.Caption = "FORM标题" Then blnFlag = True End If Next frm If blnFlag Then MsgBox "Form已经加载" Else MsgBox "Form未加载" End If
Sorry, 刚才的方法的确不行!以下方法完全可以,仅供参考(枚举) Dim frm As Object Dim blnFlag As Boolean For Each frm In Forms If frm.Caption = "FORM标题" Then blnFlag = True Exit For End If Next frm If blnFlag Then MsgBox "Form已经加载" Else MsgBox "Form未加载" End If
(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 "窗体已经被加载!", vbOKOnly
End
Else
MsgBox "窗体未被加载!", vbOKOnly
End If
MsgBox "Form未加载"
else
MsgBox "Form已加载"
end if建议不要用KillerAPP的那种方法,因为不同窗体会有相同CAPTION的.尤其是在WINDOWS中.
Dim blnFlag As Boolean
For Each frm In Forms
If frm.Caption = "FORM标题" Then
blnFlag = True
End If
Next frm
If blnFlag Then
MsgBox "Form已经加载"
Else
MsgBox "Form未加载"
End If
Dim blnFlag As Boolean
For Each frm In Forms
If frm.Caption = "FORM标题" Then
blnFlag = True
Exit For
End If
Next frm
If blnFlag Then
MsgBox "Form已经加载"
Else
MsgBox "Form未加载"
End If
既然原窗体处于加载,那它的实例也是处于加载的,所以通过判断form是否为nothing是行不通的...