C#FlaUI.UIA实现发送微信消息原理

一 准备

.NetFramework 4.8

FlaUI.UIA3 4.0.0

FlaUInspect V1.3.0

1下载FlaUInspect

https://github.com/FlaUI/FlaUInspect

FlaUInspect V1.3.0

百度网盘下载

2 NuGet 引用 flaUI.UIA3 4.0.0

二代码部分

1 引用FlaUI

复制代码
using FlaUI.Core;
using FlaUI.Core.AutomationElements;
using FlaUI.Core.Input;
using FlaUI.Core.WindowsAPI;
using FlaUI.UIA3;

2 代码全部

复制代码
 class Program
{
    //1.GetWindowText 获取给定窗口句柄的窗口标题
    [DllImport("user32.dll", CharSet = CharSet.Auto)]
    public static extern bool SwitchToThisWindow(IntPtr hWnd, bool fAltTab);
    [STAThread]//启动单一现场
    static void Main(string[] args)
    {

        Process[] processes = Process.GetProcessesByName("WeChat");
        if (processes.Count() != 1)
        {
            Console.WriteLine("微信未启动或启动多个微信");
        }
        else
        {
            //1.附加到微信进程
            using (var app = Application.Attach(processes.First().Id))
            {
                using (var automation = new UIA3Automation())
                {
                    //2.获取主界面
                    var mainWindow = app.GetMainWindow(automation);
                    //窗口置顶显示  避免其它窗口遮挡影响后续操作
                    IntPtr handle = processes.First().MainWindowHandle;
                    SwitchToThisWindow(handle, true);    // 激活,显示在最
                    var childWind = mainWindow.FindChildAt(1).FindChildAt(0).FindChildAt(1).FindChildAt(0).FindChildAt(0).FindChildAt(0);
                    childWind.DrawHighlight(System.Drawing.Color.Red);
                    childWind.Click();
                    //搜索"文件传输助手"
                    Keyboard.Type("文件传输助手");
                    Thread.Sleep(800);
                    //回车
                    Keyboard.Type(VirtualKeyShort.RETURN);
                    Thread.Sleep(800);
                    //输入内容
                    Keyboard.Type("文件传输助手");
                    Thread.Sleep(800);
                    //回车
                    Keyboard.Type(VirtualKeyShort.RETURN);




                }
            }
        }

    }
}

三 原理如下

FlaUInspect V1.3.0

查找pane 节点 1,0,1,0,0,0

找到搜索

mainWindow.FindChildAt(1 ).FindChildAt(0 ).FindChildAt(1 ).FindChildAt(0 ).FindChildAt(0 ).FindChildAt(0);

根据FlaUInspect提示信息 可以做自动化辅助工具

演示代码下载

相关推荐
暴走约伯11 小时前
【VFX工具链源码拆解 09】终极工业化闭环:基于 ID 规则驱动的全自动场景建档、骨骼挂载与男转女场景迁移
unity·c#·游戏引擎·材质
Dumbness12 小时前
关键词回复里写了 {订单号},群机器人整条消息都炸了
python·微信
用户788477316341 天前
WinForms 迁移 WPF:Upgrade Assistant 覆盖 30%,剩下 70% 我手写了六周
c#
寂寞的船2 天前
【Unity知识速递】第13期 Unity 内存泄漏排查实战:从 Memory Profiler 到 Lua 引用泄漏的生产级全链路诊断
unity·junit·c#·游戏引擎·lua
用户3721574261352 天前
C# 提取 PDF 附件:包括文档附件和页面注释附件
c#
寂寞的船2 天前
【Unity Bug挑战】第12期 Awaitable 二次 await 死锁之谜 —— 为什么同一个异步操作等两次就卡死?
unity·c#·游戏引擎·bug
huaqianzkh4 天前
WinForm C#:循环修改控件UI闪烁卡顿?SuspendLayout / ResumeLayout 与 BeginUpdate 优化
开发语言·ui·c#
用户3721574261354 天前
C# 实现 Excel 单元格保护:锁定公式并允许编辑指定区域
c#·ai编程·编程语言
公子小六5 天前
基于.NET的Windows窗体编程之WinForms数据持久化(1)
windows·microsoft·c#·.net·winforms
三雷科技5 天前
第6章第4节:自定义分词器
开发语言·c#