VB 如何得到当前任务栏在运行的所有窗体的标题

如题目。我想获得所有窗口的标题。然后分析哪个窗口是我需要的。最后就是控制该窗口,例如在QQ聊天进行输入文字、发送等操作。假如可以,当然所有都回答!假如不可以的话,就先回答... 如题目。我想获得所有窗口的标题。然后分析哪个窗口是我需要的。最后就是控制该窗口,例如在QQ聊天进行输入文字、发送等操作。假如可以,当然所有都回答!假如不可以的话,就先回答第一个啦。感谢 展开
 我来答
pvmy5813
2011-11-09 · TA获得超过286个赞
知道答主
回答量:352
采纳率:0%
帮助的人:199万
展开全部
需要api的支持,有人已经写出来了:

'获取任务栏窗体名称
Option Explicit
Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Public Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Public Declare Function IsWindowVisible Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Public Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Public Const GW_OWNER = 4

Function lpfunc(ByVal hwnd As Long, ByVal lParam As Long) As Boolean
Dim pstr As String, Ret As Long

If IsWindowVisible(hwnd) = False Then GoTo continu
If GetWindow(hwnd, GW_OWNER) <> 0 Then GoTo continu
Ret = GetWindowTextLength(hwnd)
pstr = Space(Ret)
If GetWindowText(hwnd, pstr, Ret + 1) = 0 Then GoTo continu
If pstr <> "" And pstr <> "Program Manager" Then Form1.List1.AddItem pstr

continu:
lpfunc = True
End Function

Private Sub Command1_Click()
List1.Clear
EnumWindows AddressOf lpfunc, ByVal 0&
End Sub

'根据窗体标题获取窗体句柄
Private Sub Command2_Click()
Dim i As Integer
Dim hwndNext As Long
Dim hwnd() As Long
i = 0
hwndNext = FindWindowEx(0, 0, vbNullString, "窗体标题")
Do While hwndNext <> 0
ReDim Preserve hwnd(i) As Long
hwnd(i) = hwndNext
i = i + 1
hwndNext = FindWindowEx(0, hwnd(i - 1), vbNullString, "窗体标题")
Loop
If i <> 0 Then
For i = 0 To UBound(hwnd)
List1.AddItem hwnd(i)
Next
Else
MsgBox "未找到相应标题名的窗口"
End If

End Sub

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwprocessid As Long) As Long
Dim HwndVal&, ChildHwnd&
Private Sub Command1_Click()
HwndVal = FindWindow(vbNullString, "窗体标题")
'Print "窗口句柄是:" & CStr(HwndVal) & Space(3) & "进程号是:" & CStr(ProcIDFromWnd(HwndVal))
ChildHwnd = FindWindowEx(HwndVal, 0, "Static", vbNullString)
'Text1 = "子句柄是:" & ChildHwnd
List1.AddItem CStr(HwndVal) & vbTab & CStr(ProcIDFromWnd(HwndVal)) & vbTab & ChildHwnd
End Sub
班丘晓桐0U
2011-11-09 · TA获得超过446个赞
知道小有建树答主
回答量:739
采纳率:0%
帮助的人:620万
展开全部
api函数findwindow findnext组合!
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

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

类别

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

说明

0/200

提交
取消

辅 助

模 式