vb.net QQ消息获取

Imports System
Imports System.Text
Imports System.Windows.Automation
Imports System.Runtime.InteropServices
Imports System.Collections.Generic
Imports System.Windows.Forms
Module Module1
Private Declare Function EnumWindows Lib “user32.dll” (ByVal lpEnumFunc As LPENUMWINDOWSPROC, ByVal lParam As Integer) As Boolean
Private Declare Function GetClassName Lib “user32.dll” Alias “GetClassNameA” (ByVal hWnd As Integer, ByVal buf As StringBuilder, ByVal nMaxCount As Integer) As Boolean
Private Declare Function GetWindowText Lib “user32” Alias “GetWindowTextA” (ByVal hWnd As Integer, ByVal lpString As StringBuilder, ByVal nMaxCount As Integer) As Boolean
Private Declare Function GetWindowTextLength Lib “user32” Alias “GetWindowTextLengthA” (ByVal hWnd As Integer) As Integer
Public Declare Function IsWindow Lib “user32” (ByVal hWnd As IntPtr) As Boolean
Private Delegate Function LPENUMWINDOWSPROC(ByVal hwnd As Integer, ByVal lParam As Integer) As Boolean
Public Const NULL As Integer = 0
Private Const MAXBYTE As Integer = 255
Dim hWndCollect As New List(Of Integer)
Private Function ScanSessionWindow(ByVal hwnd As Integer, ByVal lParam As Integer) As Boolean
Dim buf As StringBuilder = New StringBuilder(MAXBYTE)
If GetClassName(hwnd, buf, MAXBYTE) AndAlso buf.ToString() = “TXGuiFoundation” Then

        If GetWindowTextLength(hwnd) > 0 AndAlso GetWindowText(hwnd, buf, MAXBYTE) Then
            Dim str As String = buf.ToString()

            If str <> "TXMenuWindow" AndAlso str <> "QQ" AndAlso str <> "增加时长" Then
                Console.WriteLine(vbTab & (hWndCollect.Count + 1) & ": " & str)
                hWndCollect.Add(hwnd)
            End If
        End If
    End If

    Return True
End Function
Public Function GetSessionWindow() As Integer()
    hWndCollect = New List(Of Integer)()
    EnumWindows(AddressOf ScanSessionWindow, NULL)
    Return hWndCollect.ToArray()
End Function
Private Sub FindUserMessage(ByVal hwnd As IntPtr)
    If Not IsWindow(hwnd) Then
        Console.WriteLine("QQ session window has been closed.")
    Else
        Dim element As AutomationElement = AutomationElement.FromHandle(hwnd)
        element = element.FindFirst(TreeScope.Descendants, New PropertyCondition(AutomationElement.NameProperty, "消息")) '"消息"

        If element IsNot Nothing AndAlso element.Current.IsEnabled Then
            Dim vpTextEdit As ValuePattern = TryCast(element.GetCurrentPattern(ValuePattern.Pattern), ValuePattern)

            If vpTextEdit IsNot Nothing Then
                Dim value As String = vpTextEdit.Current.Value
                value = value.Replace(" ", "")
                value = value.Replace(vbCr, vbCrLf)
                Console.WriteLine(value)
                MessageBox.Show(value)
            End If
        End If
    End If
End Sub
<STAThread>
Sub Main(ByVal args As String())
    Console.Title = String.Empty
    Console.WriteLine("scan the QQ user's session window.")
    Dim hWndOfSession As Integer() = GetSessionWindow()

    If hWndOfSession.Length <= 0 Then
        Console.WriteLine("No scan to any available QQ message window.")
    Else
        Console.WriteLine("Look for the session record interface.")

        For Each hWnd As Integer In hWndOfSession
            FindUserMessage(CType(hWnd, IntPtr))
        Next
    End If

    Console.WriteLine("Thank you for using, QQ conversations have been scanned.")
    Console.ReadKey(False)
End Sub

End Module

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值