System.Windows.Automation.NativeMethods.WindowAtPosition C# (CSharp) Method

WindowAtPosition() public static method

public static WindowAtPosition ( int px, int py ) : IntPtr
px int
py int
return System.IntPtr
		public static IntPtr WindowAtPosition (int px, int py)
		{
			var startHandle = IntPtr.Zero;
			var topWin = TopWindowAtPosition (px, py);
			if (topWin != null)
				startHandle = GetWindowHandle (topWin);
			if (startHandle == IntPtr.Zero)
				startHandle = RootWindowHandle;
			return ChildWindowAtPosition (startHandle, px, py, false);
		}

Usage Example

示例#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));
        }