예제 #1
0
파일: WinApi.cs 프로젝트: Bluegrams/MPos
        /// <summary>
        /// Gets the dpi of the monitor.
        /// </summary>
        /// <param name="pt">A point specifying the monitor that should be used.</param>
        /// <param name="dpiType">A value of MonitorDpiType indicating the dpi type to be returned.</param>
        /// <returns>The dpi of the monitor.</returns>
        public static int GetMonitorDpiFromPoint(WinPoint pt, MonitorDpiType dpiType)
        {
            IntPtr hmonitor = MonitorFromPoint(pt, MonitorOptions.MONITOR_DEFUALTTONEAREST);

            GetDpiForMonitor(hmonitor, dpiType, out int dpiX, out int dpiY);
            return(dpiX);
        }
예제 #2
0
파일: WinApi.cs 프로젝트: Bluegrams/MPos
        /// <summary>
        /// Maps a point in screen coordinates to coordinates relative to the active window.
        /// </summary>
        /// <param name="point">A point in screen coordinates.</param>
        /// <returns>The given point in coordinates relative to the active window.</returns>
        public static WinPoint ScreenPointToClient(WinPoint point)
        {
            IntPtr hWnd = GetForegroundWindow();

            ScreenToClient(hWnd, ref point);
            return(point);
        }
예제 #3
0
        /// <summary>
        /// Returns the color of the pixel at the mouse's position.
        /// </summary>
        public static Color GetPixelColor(WinPoint point)
        {
            Bitmap bmp = new Bitmap(1, 1);

            using (Graphics g = Graphics.FromImage(bmp))
            {
                try
                {
                    g.CopyFromScreen(point.X, point.Y, 0, 0, new Size(1, 1));
                }
                catch { }
            }
            Color color = bmp.GetPixel(0, 0);

            bmp.Dispose();
            return(Color.FromArgb(color.R, color.G, color.B));
        }
예제 #4
0
        /// <summary>
        /// Creates a PositionData instance from a given point.
        /// </summary>
        public PositionData(Point position)
        {
            WinPoint winPos = (WinPoint)position;

            this.PhysicalPosition = position;
            // Determine dpi information
            this.Dpi        = WinApi.GetMonitorDpiFromPoint(winPos, MonitorDpiType.EFFECTIVE_DPI);
            this.DpiScaling = Math.Round(Dpi / (double)96, 2);
            // Determine scaled position.
            this.ScaledPosition = new Point((int)(position.X / DpiScaling),
                                            (int)(position.Y / DpiScaling));
            // Determine relative position.
            this.RelativePosition = (Point)WinApi.ScreenPointToClient(winPos);
            // Determine raw dpi.
            this.RawDpi      = WinApi.GetMonitorDpiFromPoint(winPos, MonitorDpiType.RAW_DPI);
            this.DpiRawRatio = Math.Round(Dpi / (double)RawDpi, 2);
            // Determine screen bounds
            this.ScreenResolution = Screen.FromPoint(position).Bounds.Size;
            // Determine color at mouse position.
            this.PixelColor = GetPixelColor(winPos);
        }
예제 #5
0
파일: WinApi.cs 프로젝트: Bluegrams/MPos
 private static extern IntPtr MonitorFromPoint(WinPoint pt, MonitorOptions dwFlags);
예제 #6
0
파일: WinApi.cs 프로젝트: Bluegrams/MPos
 private static extern bool ScreenToClient(IntPtr hWnd, ref WinPoint lpPoint);