WindowAtPosition() public static method

public static WindowAtPosition ( int px, int py ) : IntPtr
px int
py int
return System.IntPtr
示例#1
0
        public static AutomationElement FromPoint(Point pt)
        {
            IntPtr handle = NativeMethods.WindowAtPosition((int)pt.X, (int)pt.Y);

            if (handle == IntPtr.Zero)
            {
                return(RootElement);
            }
            AutomationElement startElement = null;

            try {
                startElement = FromHandle(handle);
            } catch (ElementNotAvailableException) {
                return(RootElement);
            }
            if (startElement == RootElement)
            {
                return(RootElement);
            }
            //Keep searching the descendant element which are not native window
            var sourceElement = startElement.SourceElement.
                                GetDescendantFromPoint(pt.X, pt.Y);

            return(SourceManager.GetOrCreateAutomationElement(sourceElement));
        }