Exemple #1
0
 /// <summary>
 /// Updates the UIElement static cache containing System DPI value
 /// </summary>
 /// <param name="systemDpiScale">Updated System DPI scale value</param>
 internal static void UpdateUIElementCacheForSystemDpi(DpiScale2 systemDpiScale)
 {
     lock (UIElement.DpiLock)
     {
         UIElement.DpiScaleXValues.Insert(0, systemDpiScale.DpiScaleX);
         UIElement.DpiScaleYValues.Insert(0, systemDpiScale.DpiScaleY);
     }
 }
            /// <summary>
            /// Gets the DPI of the monitor nearest to a window
            /// </summary>
            /// <param name="hWnd">Handle to the window</param>
            /// <returns>DPI of the monitor nearest to the window</returns>
            private static DpiScale2 GetDpiForWindowFromNearestMonitor(IntPtr hWnd)
            {
                IntPtr hMon =
                    SafeNativeMethods.MonitorFromWindow(new HandleRef(IntPtr.Zero, hWnd), NativeMethods.MONITOR_DEFAULTTONEAREST);

                uint dpiX, dpiY;
                int  hr = (int)UnsafeNativeMethods.GetDpiForMonitor(new HandleRef(IntPtr.Zero, hMon), MONITOR_DPI_TYPE.MDT_EFFECTIVE_DPI, out dpiX, out dpiY);

                // Throw if FAILED(hr)
                Marshal.ThrowExceptionForHR(hr);

                return(DpiScale2.FromPixelsPerInch(dpiX, dpiY));
            }
Exemple #3
0
            private static DpiScale2 GetSystemDpiFromDeviceCaps()
            {
                HandleRef hWndDesktop = new HandleRef(IntPtr.Zero, IntPtr.Zero);
                HandleRef hDC         = new HandleRef(IntPtr.Zero, UnsafeNativeMethods.GetDC(hWndDesktop));

                if (hDC.Handle == IntPtr.Zero)
                {
                    return(null);
                }

                try
                {
                    int ppiX = UnsafeNativeMethods.GetDeviceCaps(hDC, NativeMethods.LOGPIXELSX);
                    int ppiY = UnsafeNativeMethods.GetDeviceCaps(hDC, NativeMethods.LOGPIXELSY);

                    return(DpiScale2.FromPixelsPerInch(ppiX, ppiY));
                }
                finally
                {
                    UnsafeNativeMethods.ReleaseDC(hWndDesktop, hDC);
                }
            }
Exemple #4
0
            /// <summary>
            /// Returns the System DPI by querying the value directly.
            /// </summary>
            /// <returns>The system DPI</returns>
            private static DpiScale2 GetDpiForSystem()
            {
                uint dpi = SafeNativeMethods.GetDpiForSystem();

                return(DpiScale2.FromPixelsPerInch(dpi, dpi));
            }
            /// <summary>
            /// Gets a window's DPI by querying it directly
            /// </summary>
            /// <param name="hWnd">Handle to the window</param>
            /// <returns>The DPI of the window</returns>
            private static DpiScale2 GetDpiForWindow(IntPtr hWnd)
            {
                uint dpi = SafeNativeMethods.GetDpiForWindow(new HandleRef(IntPtr.Zero, hWnd));

                return(DpiScale2.FromPixelsPerInch(dpi, dpi));
            }
Exemple #6
0
 /// <summary>
 /// Updates the UIElement static cache containing System DPI value
 /// </summary>
 /// <param name="systemDpiScale">Updated system DPI scale value</param>
 internal static void UpdateUIElementCacheForSystemDpi(DpiScale2 systemDpiScale)
 {
     SystemDpiHelper.UpdateUIElementCacheForSystemDpi(systemDpiScale);
 }