コード例 #1
0
        void AssociatedObject_SourceInitialized(object sender, EventArgs e)
        {
            AddHwndHook();

            currentDpiRatio = MonitorDpi.GetScaleRatioForWindow(AssociatedObject);
            UpdateDpiScaling(currentDpiRatio);
        }
コード例 #2
0
        IntPtr HwndHook(IntPtr hWnd, int message, IntPtr wParam, IntPtr lParam, ref bool handled)
        {
            switch (message)
            {
            case NativeConstants.WM_DPICHANGED:
                var rect = (RECT)Marshal.PtrToStructure(lParam, typeof(RECT));

                SafeNativeMethods.SetWindowPos(hWnd, IntPtr.Zero,
                                               rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top,
                                               SetWindowPosFlags.DoNotChangeOwnerZOrder | SetWindowPosFlags.DoNotActivate | SetWindowPosFlags.IgnoreZOrder);

                var newDpiRatio = MonitorDpi.GetScaleRatioForWindow(AssociatedObject);
                if (newDpiRatio != currentDpiRatio)
                {
                    UpdateDpiScaling(newDpiRatio);
                }

                break;
            }

            return(IntPtr.Zero);
        }