Beispiel #1
0
        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);
            }
        }
Beispiel #2
0
        /// <summary>
        /// 点击toolBar句柄下某个按钮--这个有可能点不中--需要优化
        /// </summary>
        /// <param name="toolBar"></param>
        /// <param name="name"></param>
        public static bool ClickBtnByName(IntPtr toolBar, string name)
        {
            if (toolBar == IntPtr.Zero)
            {
                return(false);
            }
            //AmLogger.Info("ClickBtnByName", $"toolBar:{toolBar},name:{name}");
            try
            {
                var winBarUia = UiaHelper.GetUIAutomation().ElementFromHandle(toolBar);
                var element   = winBarUia.FindFirst(UIAutomationClient.TreeScope.TreeScope_Children, UiaHelper.GetUIAutomation().
                                                    CreatePropertyCondition(UIA_PropertyIds.UIA_NamePropertyId, name));
                Console.WriteLine($"{element.CurrentNativeWindowHandle}");
                var pattern = (IUIAutomationInvokePattern)element?.GetCurrentPattern(UIA_PatternIds.UIA_InvokePatternId);
                //var pattern = (IUIAutomationLegacyIAccessiblePattern)element?.GetCurrentPattern(UIA_PatternIds.UIA_LegacyIAccessiblePatternId);

                pattern?.Invoke();
                //pattern?.DoDefaultAction();
                Console.WriteLine("success....");
                return(true);
            }
            catch (Exception e)
            {
                Console.WriteLine($"error {e.Message}");
                //AmLogger.Error("ClickBtnUiaByName", $"{name},message:{e.Message},stacktrace:{e.StackTrace}");
            }
            return(false);
        }
Beispiel #3
0
        public static void SetCombox()
        {
            try
            {
                var comBoxMation = UiaHelper.GetUIAutomation().ElementFromHandle((IntPtr)5571680);

                //WinApi.ClickLocation((IntPtr) 5571680, 50, 20);
                //Thread.Sleep(100);

                //var childs = comBoxMation.FindAll(UIAutomationClient.TreeScope.TreeScope_Descendants,
                //    UiaHelper.GetUIAutomation().CreateTrueCondition());
                //for (var i = 0; i < childs.Length; i++)
                //{
                //    Console.WriteLine(childs.GetElement(i).CurrentName);
                //}


                var selectItem = comBoxMation?.FindFirst(UIAutomationClient.TreeScope.TreeScope_Descendants,
                                                         UiaHelper.GetUIAutomation().CreatePropertyCondition(
                                                             UIA_PropertyIds.UIA_NamePropertyId, "9%"));

                var pattern = (IUIAutomationSelectionItemPattern)selectItem?.GetCurrentPattern(UIA_PatternIds.UIA_SelectionItemPatternId);
                if (pattern == null)
                {
                    return;
                }

                pattern.Select();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Beispiel #4
0
        /// <summary>
        /// 操作航信自定义报错弹框
        /// </summary>
        static void OperatorCustomer()
        {
            var custoBar    = WinApi.FindWindow(null, "CusMessageBox");
            var editControl =
                UiaHelper.GetUIAutomation().ElementFromHandle(custoBar).FindFirst(UIAutomationClient.TreeScope.TreeScope_Descendants,
                                                                                  UiaHelper.GetUIAutomation().CreatePropertyCondition(UIA_PropertyIds.UIA_AutomationIdPropertyId, "rtbDescript"));

            var pt = (IUIAutomationValuePattern)editControl.GetCurrentPattern(UIA_PatternIds.UIA_ValuePatternId);

            Console.WriteLine(pt.CurrentValue);
        }
Beispiel #5
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();
            //}
        }