C#FlaUI.UIA implements the principle of sending WeChat messages

One preparation

.NetFramework 4.8
FlaUI.UIA3 4.0.0 

FlaUInspect V1.3.0

1Download FlaUInspect 

https://github.com/FlaUI/FlaUInspect

FlaUInspect V1.3.0

Baidu network disk download

2 NuGet quote flaUI.UIA3 4.0.0

Second code part

1 Quote FlaUI

using FlaUI.Core;
using FlaUI.Core.AutomationElements;
using FlaUI.Core.Input;
using FlaUI.Core.WindowsAPI;
using FlaUI.UIA3;

2 code all

 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);




                }
            }
        }

    }
}

 The three principles are as follows

FlaUInspect V1.3.0

Find pane node 1,0,1,0,0,0

find search

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

Automated auxiliary tools can be created based on FlaUInspect prompt information.

Demo code download

Next article: WeChat message push instance development

Guess you like

Origin blog.csdn.net/hb_ljj/article/details/134601249