取QQ会话记录

本文介绍了一个使用C#调用Win32 API的示例,展示了如何枚举并获取Windows窗口的类名和标题,特别针对QQ聊天窗口,通过自动化元素查找消息界面。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

using System;
using System.Text;
using System.Windows.Automation;
using System.Runtime.InteropServices;
using System.Collections.Generic;
using System.Windows.Forms;

public abstract partial class Win32Native
{
    [DllImport("user32.dll")]
    [return: MarshalAs(UnmanagedType.Bool)]
    private static extern bool EnumWindows(LPENUMWINDOWSPROC lpEnumFunc, int lParam);

    [DllImport("user32.dll", CharSet = CharSet.Ansi)]
    [return: MarshalAs(UnmanagedType.Bool)]
    private static extern bool GetClassName(int hWnd, StringBuilder buf, int nMaxCount);

    [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
    [return: MarshalAs(UnmanagedType.Bool)]
    private static extern bool GetWindowText(int hWnd, StringBuilder lpString, int nMaxCount);

    [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
    private static extern int GetWindowTextLength(int hWnd);

    [DllImport("user32.dll")]
    [return: MarshalAs(UnmanagedType.Bool)]
    public static extern bool IsWindow(IntPtr hWnd);

    private delegate bool LPENUMWINDOWSPROC(int hwnd, int lParam);

    public const int NULL = 0;
    private const int MAXBYTE = 255;
}

public abstract partial class Win32Native
{
    private static volatile List<int> hWndCollect;

    private static bool ScanSessionWindow(int hwnd, int lParam)
    {
        StringBuilder buf = new StringBuilder(MAXBYTE);
        if (GetClassName(hwnd, buf, MAXBYTE) && buf.ToString() == "TXGuiFoundation")
            if (GetWindowTextLength(hwnd) > 0 && GetWindowText(hwnd, buf, MAXBYTE))
            {
                string str = buf.ToString();
                if (str != "TXMenuWindow" && str != "QQ" && str != "增加时长")
                {
                    Console.WriteLine("\t" + (hWndCollect.Count + 1) + ": " + str);
                    hWndCollect.Add(hwnd);
                }
            }
        return true;
    }

    public static int[] GetSessionWindow()
    {
        hWndCollect = new List<int>();
        EnumWindows(ScanSessionWindow, NULL);
        return hWndCollect.ToArray();
    }
}

public static partial class Program
{
    private static void FindUserMessage(IntPtr hwnd)
    {
        if (!Win32Native.IsWindow(hwnd))
            Console.WriteLine("QQ session window has been closed.");
        else
        {
            AutomationElement element = AutomationElement.FromHandle(hwnd);
            element = element.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.NameProperty, "消息"));
            if (element != null && element.Current.IsEnabled)
            {
                ValuePattern vpTextEdit = element.GetCurrentPattern(ValuePattern.Pattern) as ValuePattern;
                if (vpTextEdit != null)
                {
                    string value = vpTextEdit.Current.Value;
                    Console.WriteLine(value);
                    MessageBox.Show(value);
                }
            }
        }
    }
}

public static partial class Program
{
    [STAThread]
    private static void Main(string[] args)
    {
        Console.Title = string.Empty;
        Console.WriteLine("scan the QQ user's session window.");
        int[] hWndOfSession = Win32Native.GetSessionWindow();
        if (hWndOfSession.Length <= 0)
            Console.WriteLine("No scan to any available QQ message window.");
        else
        {
            Console.WriteLine("Look for the session record interface.");
            foreach (int hWnd in hWndOfSession)
                FindUserMessage((IntPtr)hWnd);
        }
        Console.WriteLine("Thank you for using, QQ conversations have been scanned.");
        Console.ReadKey(false);
    }
}

### 扣子智能体平台功能与使用说明 #### 平台概述 扣子Coze)是由字节跳动推出的一款面向终端用户的智能体开发平台[^3]。该平台支持用户通过零代码或低代码方式快速构建基于人工智能大模型的各种智能体应用,并能够将其部署至其他网站或者通过 API 集成到现有的系统中。 #### 快速搭建智能体 无论是具备还是缺乏编程基础的用户,都能够借助扣子平台迅速创建一个 AI 智能体。例如,可以参照一篇教程中的实例来学习如何打造一个解决日常生活问题的小助手[^1]。这不仅降低了技术门槛,还使得更多的人有机会参与到智能化工具的设计过程中去。 #### 插件系统的利用 为了进一步增强所建智能体的能力,在其技能配置环节可加入不同类型的插件。一旦添加成功,则可以在编写提示语句的时候直接调用这些插件,亦或是融入自动化流程里实现更复杂操作逻辑的目的[^2]。这种灵活运用外部资源的方法极大地拓宽了单个智能体所能覆盖的应用场景范围。 ```python # 示例:假设我们有一个简单的 Python 脚本用于模拟调用某个插件功能 def call_plugin(plugin_name, parameters): result = f"Plugin {plugin_name} called with params: {parameters}" return result example_call = call_plugin("weather", {"location": "Beijing"}) print(example_call) ``` 上述代码片段仅作为概念展示之用,实际情况下具体实现会依据官方文档指导完成。 #### 总结 综上所述,扣子智能体平台提供了便捷高效的途径让用户无需深厚编码背景即可打造出满足特定需求的AI解决方案;同时它开放性强允许接入第三方服务从而提升整体性能表现。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值