vb已知窗体类名,获取窗体名称

 我来答
帐号已注销
2012-08-20 · 超过22用户采纳过TA的回答
知道答主
回答量:108
采纳率:0%
帮助的人:64万
展开全部
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
网海1书生
科技发烧友

2012-08-06 · 擅长软件设计、WEB应用开发、小程序
网海1书生
采纳数:12311 获赞数:26228

向TA提问 私信TA
展开全部
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
本回答被网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
zx001z7d53
2012-08-06 · TA获得超过2万个赞
知道大有可为答主
回答量:2.4万
采纳率:52%
帮助的人:5642万
展开全部
如果只有一个同类型的窗体被打开,可以解决
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式