VB如何获取当前聊天窗口QQ号和聊天内容?

解决方案 »

  1.   

    Private Declare Function GetDesktopWindow Lib "user32" () As Long
    Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
    Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
    Const WM_SETTEXT = &HC
    Const WM_CHAR = &H102
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    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 Const GW_CHILD = 5
    Private Const GW_HWNDNEXT = 2
    Private Handle As LongPrivate Sub Command1_Click()
    Dim hwnd As Long
    '取得桌面窗口
    hwnd = GetDesktopWindow()
    '取得桌面窗口的第一个子窗口
    hwnd = GetWindow(hwnd, GW_CHILD)Dim strTitle As String * 255 '用来存储窗口的标题'通过循环来枚举所有的窗口
    Do While hwnd <> 0
    '取得下一个窗口的标题
    GetWindowText hwnd, strTitle, Len(strTitle)
    If Left$(strTitle, 1) <> vbNullChar Then
    If InStr(Left$(strTitle, InStr(1, strTitle, vbNullChar)), "交谈中") > 0 Then '检查是否包含定义的字符
        tmp1 = hwnd
        t1 = FindWindowEx(tmp, 0, "AfxWnd42", "")
        t2 = FindWindowEx(t1, 0, "RichEdit20A", "")
        SendMessage t2, WM_CHAR, Asc("中"), &H0
        SendMessage t2, WM_CHAR, Asc("文"), &H0
    End If
    End If
    '调用GetWindow函数,来取得下一个窗口
    hwnd = GetWindow(hwnd, GW_HWNDNEXT)
    Loop
    End Sub
    解决乐请给分啊?
      

  2.   

    最简单实现
    Set Q = CreateObject("wscript.Shell")
            If Q.AppActivate("交谈中") = True Then
                Q.SendKeys "哈哈,自动喊话"
                Q.SendKeys "{ENTER}"
    End If'--------------------------不像是 “与 XX 交谈中” 那么容易吧- - 
    把"#32770"改为vbNullString试试下面这个可以查找标题带有“交谈中”的窗口
    先复制API
    Private Declare Function GetDesktopWindow Lib "user32" () As Long
    Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) 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 Const GW_CHILD = 5
    Private Const GW_HWNDNEXT = 2
    Private Handle As Long
    然后放这些东西
    Dim hwnd As Long
    '取得桌面窗口
    hwnd = GetDesktopWindow()
    '取得桌面窗口的第一个子窗口
    hwnd = GetWindow(hwnd, GW_CHILD)Dim strTitle As String * 255 '用来存储窗口的标题'通过循环来枚举所有的窗口
    Do While hwnd <> 0
        '取得下一个窗口的标题
        GetWindowText hwnd, strTitle, Len(strTitle)
        If Left$(strTitle, 1) <> vbNullChar Then
        If InStr(Left$(strTitle, InStr(1, strTitle, vbNullChar)), "交谈中") > 0 Then '检查是否包含定义的字符
            '要做什么就这里做
            '例如SendMessage
            '你的tmp1在这里等于hwnd
            tmp1 = hwnd
        End If
    End If
    '调用GetWindow函数,来取得下一个窗口
    hwnd = GetWindow(hwnd, GW_HWNDNEXT)
    Loop  0