vb已知窗体类名,获取窗体名称
展开全部
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindowText Lib "user32.dll" Alias "GetWindowTextA" (ByVal hWnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function GetWindowTextLength Lib "user32.dll" Alias "GetWindowTextLengthA" (ByVal hWnd As Long) As Long
Function 查找窗口句柄(窗口类名,窗口标题)
If Cstr(窗口类名) = "0" Then
查找窗口句柄 = FindWindow(vbNullString, Cstr(窗口标题))
ElseIf Cstr(窗口标题) = "0" Then
查找窗口句柄 = FindWindow(Cstr(窗口类名), vbNullString)
Else
查找窗口句柄 = FindWindow(Cstr(窗口类名), Cstr(窗口标题))
End If
End Function
'示例:根据类名查找句柄:hwnd = 查找窗口句柄("TXGuifoundation",0)
'根据窗口句柄得到该窗口的标题
Function getCaption(hWnd As Long)
Dim hWndlength As Long, hWndTitle As String, A As Long
hWndlength = GetWindowTextLength(hWnd)
hWndTitle = String$(hWndlength, 0)
A = GetWindowText(hWnd, hWndTitle, (hWndlength + 1))
getCaption = hWndTitle
End Function
Private Declare Function GetWindowText Lib "user32.dll" Alias "GetWindowTextA" (ByVal hWnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function GetWindowTextLength Lib "user32.dll" Alias "GetWindowTextLengthA" (ByVal hWnd As Long) As Long
Function 查找窗口句柄(窗口类名,窗口标题)
If Cstr(窗口类名) = "0" Then
查找窗口句柄 = FindWindow(vbNullString, Cstr(窗口标题))
ElseIf Cstr(窗口标题) = "0" Then
查找窗口句柄 = FindWindow(Cstr(窗口类名), vbNullString)
Else
查找窗口句柄 = FindWindow(Cstr(窗口类名), Cstr(窗口标题))
End If
End Function
'示例:根据类名查找句柄:hwnd = 查找窗口句柄("TXGuifoundation",0)
'根据窗口句柄得到该窗口的标题
Function getCaption(hWnd As Long)
Dim hWndlength As Long, hWndTitle As String, A As Long
hWndlength = GetWindowTextLength(hWnd)
hWndTitle = String$(hWndlength, 0)
A = GetWindowText(hWnd, hWndTitle, (hWndlength + 1))
getCaption = hWndTitle
End Function
展开全部
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Sub Command1_Click()
Dim n As Long, s As String, l As Long
n = FindWindow("窗体类名", vbNullString)
If n<>0 Then
s = String(200, 0)
l = GetWindowText(n, s, 200)
s = Trim(Left(s, l))
If s <> "" Then MsgBox "窗体的标题是:" & s
End If
End Sub
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Sub Command1_Click()
Dim n As Long, s As String, l As Long
n = FindWindow("窗体类名", vbNullString)
If n<>0 Then
s = String(200, 0)
l = GetWindowText(n, s, 200)
s = Trim(Left(s, l))
If s <> "" Then MsgBox "窗体的标题是:" & s
End If
End Sub
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
如果只有一个同类型的窗体被打开,可以解决
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询