Beispiel #1
0
        /// <summary>
        /// Get DesktopElement from x, y position
        /// </summary>
        /// <param name="xPos"></param>
        /// <param name="yPos"></param>
        /// <returns></returns>
        public static DesktopElement ElementFromPoint(int xPos, int yPos)
        {
            try
            {
                var uia = UIAutomation.ElementFromPoint(new tagPOINT()
                {
                    x = xPos, y = yPos
                });

                if (!DesktopElement.IsFromCurrentProcess(uia))
                {
#pragma warning disable CA2000 // Call IDisposable.Dispose()
                    var e = new DesktopElement(uia, true, false);
#pragma warning restore CA2000
                    e.PopulateMinimumPropertiesForSelection();

                    return(e);
                }
                else
                {
                    Marshal.ReleaseComObject(uia);
                }
            }
#pragma warning disable CA1031 // Do not catch general exception types
            catch (Exception e)
            {
                e.ReportException();
            }
#pragma warning restore CA1031 // Do not catch general exception types

            return(null);
        }
        public AutomationElement FromPoint(Point pt)
        {
            IUIAutomationElement pElement;

            pAutomation.ElementFromPoint(pt, out pElement);
            return(pElement == null ? null : new AutomationElement(pElement, this));
        }
        public static AutomationElement FromPoint(Point pt)
        {
            IUIAutomationElement elem;

            pAutomation.ElementFromPoint(pt, out elem);
            return((elem == null) ? null : new AutomationElement(elem));
        }
Beispiel #4
0
 public AutomationElement FromPoint(Point pt)
 {
     try {
         IUIAutomationElement pElement;
         pAutomation.ElementFromPoint(pt, out pElement);
         return(pElement == null ? null : new AutomationElement(pElement, this));
     }
     catch (COMException) {
         return(null);
     }
 }