static void ClickRedChar() { var winBar = WinApi.FindWindow(null, "开具增值税专用发票"); var childs = WinApi.EnumChildWindowsCallback(winBar); var toolBar = childs[childs.Count - 1].hWnd; HxShengQing.ClickBtnByName(toolBar, "红字"); Thread.Sleep(1000); var winBarUia = UiaHelper.GetUIAutomation().ElementFromHandle(winBar); var dropDown = winBarUia.FindFirst(UIAutomationClient.TreeScope.TreeScope_Children, UiaHelper.GetUIAutomation().CreatePropertyCondition( UIA_PropertyIds.UIA_NamePropertyId, "DropDown")); Console.WriteLine(JsonConvert.SerializeObject(dropDown.CurrentBoundingRectangle)); var dropChilds = dropDown.FindAll(UIAutomationClient.TreeScope.TreeScope_Children, UiaHelper.GetUIAutomation().CreateTrueCondition()); Console.WriteLine(JsonConvert.SerializeObject(dropChilds.GetElement(2).CurrentBoundingRectangle)); var pt = (IUIAutomationInvokePattern)dropChilds.GetElement(2).GetCurrentPattern(UIA_PatternIds.UIA_InvokePatternId); pt.Invoke(); var toolChilds = AutomationElement.FromHandle(toolBar) .FindAll(TreeScope.Descendants, Condition.TrueCondition); for (var i = 0; i < toolChilds.Count; i++) { Console.WriteLine(toolChilds[i].Current.Name); } }
/// <summary> /// 点击登录按钮--没有实现遮挡问题 /// </summary> static void ClickLogin() { var loginWin = WinApi.FindWindow(null, "LoginForm"); var list = WinApi.EnumChildWindowsCallback(loginWin); var loginBtn = list.Find(bar => bar.szWindowName == "登录"); WinApi.LeftClick(loginBtn.hWnd); }
static void Test() { var winBar = WinApi.FindWindow(null, "开具增值税普通发票"); var childs = WinApi.EnumChildWindowsCallback(winBar); var toolStrip = childs[childs.Count - 1].hWnd; ClickBtnByName(toolStrip, "红字"); }
static void JuanPiaoCuoWuMingXi() { var bar = WinApi.FindWindow(null, "SysMessageBox"); if (bar != IntPtr.Zero) { var list = WinApi.EnumChildWindowsCallback((IntPtr)bar); throw new Exception(list[4].szWindowName); } }
static void OperatorSys() { var winBar = WinApi.FindWindow(null, "SysMessageBox"); var bars = WinApi.EnumChildWindowsCallback(winBar); for (var i = 0; i < bars.Count; i++) { Console.WriteLine($"bars[{i}].szWindowName:{bars[i].szWindowName},bars[i].szTextName:{bars[i].szTextName}"); } }
public static int GetHwByTitle(int loginHw, string title) { var listInfos = WinApi.EnumChildWindowsCallback((IntPtr)loginHw); try { for (var i = 0; i < listInfos.Count; i++) { if (!string.IsNullOrEmpty(listInfos[i].szWindowName) && listInfos[i].szWindowName.Contains(title)) { return((int)listInfos[i].hWnd); } } } catch (Exception e) { } return(0); }
static void SearchInputFail() { WinApi.GetWindowRect(new HandleRef(null, (IntPtr)1901104), out var rectbefore); WinApi.MoveWindow((IntPtr)1901104, 10, 10, 3000, 2000, true); WinApi.GetWindowRect(new HandleRef(null, (IntPtr)1901104), out var rectbeafter); //Thread.Sleep(60000); //var formBar = WinApi.FindWindow(null, "票易通发票助手"); var winBar = WinApi.FindWindow(null, "增值税发票税控开票软件(金税盘版) V2.2.34.190728"); var child1s = WinApi.EnumChildWindowsCallback(winBar); var HmSearchBar = child1s.Find(b => b.szWindowName == "选择发票号码查询" || b.szTextName == "选择发票号码查询").hWnd; var childs = WinApi.FindChildInfo(HmSearchBar); var bar = childs.Find(b => b.szWindowName == "报送状态" || b.szTextName == "报送状态").hWnd; //WinApi.ClickLocation(bar, 5, 15); WinApi.ClickLocation(bar, 5, 15); Thread.Sleep(1000); //198352, var editControl = UiaHelper.GetUIAutomation().ElementFromHandle(winBar).FindFirst(UIAutomationClient.TreeScope.TreeScope_Descendants, UiaHelper.GetUIAutomation().CreatePropertyCondition(UIA_PropertyIds.UIA_AutomationIdPropertyId, "198352")); //var editControls = UiaHelper.GetUIAutomation().ElementFromHandle(winBar).FindAll(UIAutomationClient.TreeScope.TreeScope_Descendants, // UiaHelper.GetUIAutomation().CreatePropertyCondition( // UIA_PropertyIds.UIA_ControlTypePropertyId,UIA_ControlTypeIds.UIA_EditControlTypeId)); //for (var i = 0; i < editControls.Length; i++) //{ // var element = editControls.GetElement(i); // var pt = (IUIAutomationValuePattern)element.GetCurrentPattern(UIA_PatternIds.UIA_ValuePatternId); // if (i == 0) // pt.SetValue("chenchangchenchang"); // Console.WriteLine($"CurrentName:{element.CurrentName} ,currentValue:{pt.CurrentValue}"); //} //var child = UiaHelper.GetUIAutomation().ElementFromHandle(winBar).FindAll( // UIAutomationClient.TreeScope.TreeScope_Children, // UiaHelper.GetUIAutomation().CreateTrueCondition()); //for (var i = 0; i < child.Length; i++) //{ // Console.WriteLine(child.GetElement(i).CurrentName); //} //var elements = child.GetElement(1).FindAll(UIAutomationClient.TreeScope.TreeScope_Children, // UiaHelper.GetUIAutomation().CreateTrueCondition()); //for (var i = 0; i < elements.Length; i++) //{ // Console.WriteLine(elements.GetElement(i).CurrentName); //} //var elements = UiaHelper.GetUIAutomation().ElementFromHandle(bar).FindAll( // UIAutomationClient.TreeScope.TreeScope_Descendants, // UiaHelper.GetUIAutomation().CreateTrueCondition()); //for (var i = 0; i < elements.Length; i++) //{ // var ele = elements.GetElement(i); // Console.WriteLine(ele.CurrentName); //} //var element = UiaHelper.GetUIAutomation().ElementFromHandle(bar).FindFirst( // UIAutomationClient.TreeScope.TreeScope_Children, // UiaHelper.GetUIAutomation().CreateTrueCondition()); //if (element != null) //{ // var pt = (IUIAutomationLegacyIAccessiblePattern) element.GetCurrentPattern( // patternId: UIA_PatternIds.UIA_LegacyIAccessiblePatternId); // pt.DoDefaultAction(); //} }