Exemple #1
0
        internal void Initialize(Window window, FrameworkElement element = null)
        {
            if (window == null)
            {
                throw new ArgumentNullException(nameof(window));
            }

            if (!window.IsInitialized)
            {
                throw new InvalidOperationException("Target Window has not been initialized.");
            }

            _targetWindow  = window;
            _targetElement = element;

            ForbearScaling = WillForbearScalingIfUnnecessary && BuiltinFunction.IsScalingSupported(_targetWindow);

            if (IsPerMonitorDpiAware)
            {
                MonitorDpi = DpiChecker.GetDpiFromVisual(_targetWindow);

                if (MonitorDpi.Equals(SystemDpi) || ForbearScaling)
                {
                    WindowDpi = MonitorDpi;
                }
                else
                {
                    var newInfo = new WindowInfo
                    {
                        Dpi    = MonitorDpi,
                        Width  = _targetWindow.Width * (double)MonitorDpi.X / SystemDpi.X,
                        Height = _targetWindow.Height * (double)MonitorDpi.Y / SystemDpi.Y,
                    };

                    Interlocked.Exchange(ref _dueInfo, newInfo);

                    ChangeDpi();
                }
            }
            else
            {
                MonitorDpi = SystemDpi;
                WindowDpi  = MonitorDpi;
            }

            ColorProfilePath = ColorProfileChecker.GetColorProfilePath(_targetWindow);

            _targetSource = PresentationSource.FromVisual(_targetWindow) as HwndSource;
            _targetSource?.AddHook(WndProc);
        }
Exemple #2
0
        private void ChangeColorProfilePath()
        {
            var newPath = ColorProfileChecker.GetColorProfilePath(_targetWindow);

            if (ColorProfilePath.Equals(newPath, StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            var oldPath = ColorProfilePath;

            ColorProfilePath = newPath;

            ColorProfileChanged?.Invoke(this, new ColorProfileChangedEventArgs(oldPath, ColorProfilePath));
        }