Exemplo n.º 1
0
        private static void SetWindowDpi(IntPtr hwnd, Window window, Int32Rect windowBounds)
        {
            var structure       = RECT.FromInt32Rect(windowBounds);
            var monitorDpiScale = GetMonitorDpiScale(windowBounds.X, windowBounds.Y);
            var wParam          = new IntPtr((int)monitorDpiScale.PixelsPerInchX | (int)monitorDpiScale.PixelsPerInchY << 16);
            var num             = Marshal.AllocCoTaskMem(Marshal.SizeOf(structure));

            try
            {
                Marshal.StructureToPtr(structure, num, false);
                NativeMethods.NativeMethods.SendMessage(hwnd, 736, wParam, num);
                VisualTreeHelper.SetRootDpi(window, monitorDpiScale);
            }
            finally
            {
                Marshal.FreeCoTaskMem(num);
            }
        }