コード例 #1
0
        private void DisplaySettingsChanged(object sender, EventArgs e)
        {
            //resolve any screen orientation change
            DisplayUtil.CheckScreenOrientation(Handle);
            //end

            double oldLeft = this.Left;
            double oldTop  = this.Top;

            //resolve this problem: if screen resolution change, video windows show improperly
            //this.ChangeWindowState(WindowState.Normal);//if window is minimized, codes below will not get right result
            this.RestoreWindow(); //if window is minimized, codes below will not get right result
            Screen screen = DpiUtil.GetScreenByHandle(Handle);

            double ratio = 1;

            try
            {
                uint dpiX = 0;
                uint dpiY = 0;
                DpiUtil.GetDpiByScreen(screen, out dpiX, out dpiY);
                ratio = dpiX / 96d;
                if (ratio <= 0)
                {
                    ratio = 1;
                }
            }
            catch (DllNotFoundException ex)
            {
                ratio = 1;
                log.Warn("Cannot adjust window size for : " + ex.Message);
            }

            if (this.Left >= screen.Bounds.Left / ratio && this.Left < ((screen.Bounds.Left + screen.Bounds.Width) / ratio))
            {
                //window is not cross screen, nothing todo
            }
            else
            {
                //reset default size when window cross screen
                double height = screen.Bounds.Height / 1.2d;
                double width  = height * _initialWidth / _initialHeight;

                Utils.MySetWindowPos(Handle, new Rect(screen.Bounds.Left + (screen.Bounds.Width - width) / 2, screen.Bounds.Top + (screen.Bounds.Height - height) / 2, width, height));
                _displaySettingChangedTime = DateTime.Now;
                //do this trick to refresh layout of all the video windows
                this.MinimizeWindow();
                this.RestoreWindow();
                //end
            }
        }
コード例 #2
0
        private void FullScreenBaseWindow_Loaded(object sender, RoutedEventArgs e)
        {
            HwndSource hwndSource = (HwndSource)HwndSource.FromVisual((Window)sender);

            hwndSource.AddHook(DragHook);
            this.StateChanged += FullScreenBaseWindow_StateChanged;

            _aspectRatio = _initialWidth / (_initialHeight - _titlebarHeight);

            Handle = new WindowInteropHelper(this).Handle;

            DisplayUtil.CheckScreenOrientation(Handle);
            Microsoft.Win32.SystemEvents.DisplaySettingsChanged += new System.EventHandler(DisplaySettingsChanged);

            DpiX = 96d;
            DpiY = 96d;
            UpdateDpiValue();
            if (!_notAdjustSizeOnLoaded)
            {
                AdjustWindowSize();
            }
        }