一 準備
.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提示信息 可以做自動化輔助工具
演示代碼下載