当前位置:   article > 正文

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

flaui.uia3

一 准备

.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

  1. using FlaUI.Core;
  2. using FlaUI.Core.AutomationElements;
  3. using FlaUI.Core.Input;
  4. using FlaUI.Core.WindowsAPI;
  5. using FlaUI.UIA3;

2   代码全部

  1. class Program
  2. {
  3. //1.GetWindowText 获取给定窗口句柄的窗口标题
  4. [DllImport("user32.dll", CharSet = CharSet.Auto)]
  5. public static extern bool SwitchToThisWindow(IntPtr hWnd, bool fAltTab);
  6. [STAThread]//启动单一现场
  7. static void Main(string[] args)
  8. {
  9. Process[] processes = Process.GetProcessesByName("WeChat");
  10. if (processes.Count() != 1)
  11. {
  12. Console.WriteLine("微信未启动或启动多个微信");
  13. }
  14. else
  15. {
  16. //1.附加到微信进程
  17. using (var app = Application.Attach(processes.First().Id))
  18. {
  19. using (var automation = new UIA3Automation())
  20. {
  21. //2.获取主界面
  22. var mainWindow = app.GetMainWindow(automation);
  23. //窗口置顶显示 避免其它窗口遮挡影响后续操作
  24. IntPtr handle = processes.First().MainWindowHandle;
  25. SwitchToThisWindow(handle, true); // 激活,显示在最
  26. var childWind = mainWindow.FindChildAt(1).FindChildAt(0).FindChildAt(1).FindChildAt(0).FindChildAt(0).FindChildAt(0);
  27. childWind.DrawHighlight(System.Drawing.Color.Red);
  28. childWind.Click();
  29. //搜索"文件传输助手"
  30. Keyboard.Type("文件传输助手");
  31. Thread.Sleep(800);
  32. //回车
  33. Keyboard.Type(VirtualKeyShort.RETURN);
  34. Thread.Sleep(800);
  35. //输入内容
  36. Keyboard.Type("文件传输助手");
  37. Thread.Sleep(800);
  38. //回车
  39. Keyboard.Type(VirtualKeyShort.RETURN);
  40. }
  41. }
  42. }
  43. }
  44. }

 三 原理如下

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提示信息 可以做自动化辅助工具

演示代码下载

下一篇:微信消息推送 实例开发

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号