Пример #1
0
        /// <summary>
        /// Get the dimensions of the specified window. Includes location and size.
        /// </summary>
        /// <param name="hWnd">The handle to the window.</param>
        /// <returns>The dimensions of the window.</returns>
        public static Rectangle GetDimensions(IntPtr hWnd)
        {
            Structs.Rect hWndRect = new Structs.Rect();
            WinAPI.GetWindowRect(hWnd, out hWndRect);

            return(new Rectangle(hWndRect.X, hWndRect.Y, hWndRect.Width, hWndRect.Height));
        }
Пример #2
0
        /// <summary>
        /// Convert a global coordinate to a window coordinate.
        /// </summary>
        /// <param name="hWnd">The handle to the window.</param>
        /// <param name="x">The x coordinate.</param>
        /// <param name="y">The y coordinate.</param>
        /// <returns>The coordinate.</returns>
        public static Point ConvertToWindowCoordinates(IntPtr hWnd, int x, int y)
        {
            Structs.Rect hWndRect = new Structs.Rect();
            WinAPI.GetWindowRect(hWnd, out hWndRect);
            Point point = new Point(hWndRect.X + x, hWndRect.Y + y);

            return(point);
        }
Пример #3
0
        /// <summary>
        /// Get the mouse position relative to the top left corner of a window.
        /// </summary>
        /// <param name="hWnd">The handle to the window.</param>
        /// <param name="x">The x coordinate.</param>
        /// <param name="y">The y coordinate.</param>
        /// <returns>The mouse position.</returns>
        public static Point GetCoordinateRelativeToWindow(IntPtr hWnd)
        {
            Structs.Rect hWndRect = new Structs.Rect();
            WinAPI.GetWindowRect(hWnd, out hWndRect);
            int   x     = Cursor.Position.X;
            int   y     = Cursor.Position.Y;
            Point point = new Point(x - hWndRect.X, y - hWndRect.Y);

            return(point);
        }
Пример #4
0
 internal static extern bool GetWindowRect(IntPtr hWnd, out Structs.Rect lpRect);