Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Sub Command1_Click()
Label1.Caption = FindWindow(vbNullString, "该窗体的标题名")
End Sub
'------------------------------------------根据标题取句柄
'========================方法一========================
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Sub Command1_Click()
Text1 = FindWindow("Notepad", vbNullString) '"Notepad"为记事本的类名
End Sub
'注意如果有两个相同类名的窗体,则返回最靠前窗体的句柄
'-----------------------------------------根据类名取句柄
'========================方法二========================