下面的代码,可以获取到QQ2008的聊天窗口,但是在2009上无法使用,请问如何能获取到2009的聊天窗口?
Private Sub Command1_Click()
List1.Clear
Dim qqname As String * 255
Dim qqhwnd As Long
qqhwnd = FindWindowEx(0, 0, "#32770", vbNullString)
qqname = String(255, Chr(0))
GetWindowText qqhwnd, qqname, Len(qqname) - 1
Do Until qqhwnd = 0
If InStr(qqname, "交谈中") > 0 Or InStr(qqname, "群") > 0 Then
List1.AddItem qqname
End If
qqhwnd = FindWindowEx(0, qqhwnd, "#32770", vbNullString)
qqname = String(255, Chr(0))
GetWindowText qqhwnd, qqname, Len(qqname) - 1
Loop
End Sub
Private Sub Command1_Click()
List1.Clear
Dim qqname As String * 255
Dim qqhwnd As Long
qqhwnd = FindWindowEx(0, 0, "#32770", vbNullString)
qqname = String(255, Chr(0))
GetWindowText qqhwnd, qqname, Len(qqname) - 1
Do Until qqhwnd = 0
If InStr(qqname, "交谈中") > 0 Or InStr(qqname, "群") > 0 Then
List1.AddItem qqname
End If
qqhwnd = FindWindowEx(0, qqhwnd, "#32770", vbNullString)
qqname = String(255, Chr(0))
GetWindowText qqhwnd, qqname, Len(qqname) - 1
Loop
End Sub
Private Type PROCESSENTRY32
dwSize As Long
cntUsage As Long
th32ProcessID As Long
th32DefaultHeapID As Long
th32ModuleID As Long
cntThreads As Long
th32ParentProcessID As Long
pcPriClassBase As Long
dwFlags As Long
szExeFile As String * 1024
End Type Private Type MODULEENTRY32
dwSize As Long
th32ModuleID As Long
th32ProcessID As Long
GlblcntUsage As Long
ProccntUsage As Long
modBaseAddr As Byte
modBaseSize As Long
hModule As Long
szModule As String * 256
szExePath As String * 1024
End Type Const TH32CS_SNAPHEAPLIST = &H1
Const TH32CS_SNAPPROCESS = &H2
Const TH32CS_SNAPTHREAD = &H4
Const TH32CS_SNAPMODULE = &H8
Const TH32CS_SNAPALL = (TH32CS_SNAPHEAPLIST Or TH32CS_SNAPPROCESS Or TH32CS_SNAPTHREAD Or TH32CS_SNAPMODULE)
Const TH32CS_INHERIT = &H80000000
Private Declare Function CreateToolhelp32Snapshot Lib "kernel32" (ByVal dwFlags As Long, ByVal th32ProcessID As Long) As Long
Private Declare Function Process32First Lib "kernel32" (ByVal hSnapshot As Long, lppe As PROCESSENTRY32) As Long
Private Declare Function Process32Next Lib "kernel32" (ByVal hSnapshot As Long, lppe As PROCESSENTRY32) As Long Function GetProcessID(EXEName As String, ProcessID As Long) As Boolean
Dim my As PROCESSENTRY32
Dim l As Long l = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0)
If l Then
my.dwSize = 1060
If (Process32First(l, my)) Then
Do
If UCase$(Right$(Left$(my.szExeFile, InStr(1, my.szExeFile, Chr$(0)) - 1)), Len(EXEName)) = UCase$(EXEName) Then
CloseHandle l
ProcessID = my.th32ProcessID
GetProcessID = True
Exit Function
End If
Loop Until (Process32Next(l, my) < 1)
End If
CloseHandle l
End If GetProcessID = False
End Function 调用方法
Global QQProcessID As Long ‘模块全局变量
Dim QQExeName As String
Dim a As Boolean QQExeName = "qq.exe"
a = GetProcessID(QQExeName, QQProcessID)
如果 a 是True 就是找到了QQ进程 '遍历窗口
Private Function EnumWindowsProc(ByVal hwnd As Long, ByVal lParam As Long) As Boolean
Dim lpdwProcessId As Long
GetWindowThreadProcessId hwnd, lpdwProcessId If lpdwProcessId = lParam Then
If GetParent(hwnd) = 0 Then Form1.List1.AddItem hwnd
End If EnumWindowsProc = True
End Function Public Sub FindQQWindow(QQProcessID As Long)
Call EnumWindows(AddressOf EnumWindowsProc, QQProcessID) End Sub
QQ2009的聊天窗口的类名已经不是#32770,而是TXGuiFoundation。