汗,测试了一下,没有完善的方法,只能大致获取,参考代码
全局代码
Public Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As EnumWindowsProc, ByVal lParam As Integer) As Integer
Public Delegate Function EnumWindowsProc(ByVal hwnd As Integer, ByVal lParam As Integer) As Boolean
Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Integer, ByVal lpString As StringBuilder, ByVal cch As Integer) As Integer
<DllImport("user32.dll")> _
Public Function GetWindowTextLength(hWnd As Integer) As Integer
End Function
Public Function EnumWindowsProcCallBack(ByVal hwnd As Integer, ByVal lParam As Integer) As Boolean
Return Functions.Execute("EnumWindowsProcCallBack", hwnd, lparam)
End Function
<DllImport("user32.dll")> _
Public Function GetWindowThreadProcessId(hWnd As Integer, ByRef pid As Integer) As Integer
End Function
内部函数 EnumWindowsProcCallBack
Dim hwnd As Integer = args(0)
Dim len As Integer = GetWindowTextLength(hWnd) + 1
Dim s As new StringBuilder(len)
If GetWindowText(hwnd, s, len ) > 0 Then
Dim pid As Integer
GetWindowThreadProcessId(hwnd, pid)
If vars("ls").contains(pid) Then
output.show(s.Tostring)
End If
End If
Return True
调用代码
vars("ls") = new List(Of String)
Dim ps As System.Diagnostics.Process() = System.Diagnostics.Process.GetProcessesByName("QQ")
For Each p As System.Diagnostics.Process In ps
vars("ls").add(p.id)
Next
Dim CallBack As New EnumWindowsProc(AddressOf EnumWindowsProcCallBack)
EnumWindows(CallBack, 0)