예제 #1
0
        private Screen(IntPtr monitor)
        {
            var info = new User32.MONITORINFO()
            {
                cbSize = Marshal.SizeOf <User32.MONITORINFO>()
            };

            if (User32.GetMonitorInfoW(monitor, ref info))
            {
                PhysicalDisplayArea = info.rcMonitor.ToRect();
                PhysicalWorkingArea = info.rcWork.ToRect();
                IsPrimary           = (info.dwFlags & User32.MONITORINFOF_PRIMARY) != 0;
            }
            uint dpix = 96, dpiy = 96;

            try {
                Shcore.GetDpiForMonitor(monitor, Shcore.MONITOR_DPI_TYPE.MDT_EFFECTIVE_DPI, ref dpix, ref dpiy);
            }
            catch (DllNotFoundException) {
            }
            catch (EntryPointNotFoundException) {
            }
            DpiX = (int)dpix;
            DpiY = (int)dpiy;
        }
예제 #2
0
    internal static int GetScreenDpi(Screen currentScreen)
    {
        if (IsPerMonitorV2Awareness)
        {
            var hMonitor = User32.MonitorFromPoint(new POINT(currentScreen.Bounds.X + currentScreen.Bounds.Width / 2, currentScreen.Bounds.Y + currentScreen.Bounds.Height / 2), MonitorOptions.MONITOR_DEFAULTTONEAREST);

            Shcore.GetDpiForMonitor(hMonitor, DpiType.Effective, out var dpiX, out var dpiY);
            return((int)dpiY);
        }

        return(DeviceDpi);
    }
예제 #3
0
    internal static int GetScreenDpiFromPoint(Point point)
    {
        if (IsPerMonitorV2Awareness)
        {
            var hMonitor = User32.MonitorFromPoint(new POINT(point), MonitorOptions.MONITOR_DEFAULTTONEAREST);

            Shcore.GetDpiForMonitor(hMonitor, DpiType.Effective, out var dpiX, out var dpiY);
            return((int)dpiY);
        }

        return(DeviceDpi);
    }
예제 #4
0
    internal static float GetScaleFactorForCurrentWindow(IntPtr handle)
    {
        if (IsPerMonitorV2Awareness)
        {
            var hMonitor = User32.MonitorFromWindow(handle, User32.MONITOR_DEFAULTTONEAREST);

            Shcore.GetDpiForMonitor(hMonitor, DpiType.Effective, out var dpiX, out var dpiY);

            return(dpiX / LOGICAL_DPI);
        }

        return(DeviceDpi / LOGICAL_DPI);
    }
예제 #5
0
    internal static int GetDpiForCurrentWindow(IntPtr handle)
    {
        if (IsPerMonitorV2Awareness)
        {
            var hMonitor = User32.MonitorFromWindow(handle, User32.MONITOR_DEFAULTTONEAREST);

            Shcore.GetDpiForMonitor(hMonitor, DpiType.Effective, out var dpiX, out var dpiY);

            return((int)dpiX);
        }

        return(DeviceDpi);
    }