A window instance that is capable of per-monitor DPI awareness when supported.
Inheritance: System.Windows.Window
コード例 #1
0
ファイル: DpiAwareWindow.cs プロジェクト: gro-ove/actools
 private void DimOwner() {
     _dimmedOwner = Owner as DpiAwareWindow;
     if (_dimmedOwner?.IsDimmed == false) {
         _dimmedOwner.IsDimmed = true;
     } else {
         _dimmedOwner = null;
     }
 }
コード例 #2
0
 private void UndimOwner()
 {
     if (_dimmedOwner != null)
     {
         _dimmedOwner.IsDimmed = false;
         _dimmedOwner          = null;
     }
 }
コード例 #3
0
 private void DimOwner()
 {
     _dimmedOwner = Owner as DpiAwareWindow;
     if (_dimmedOwner?.IsDimmed == false)
     {
         _dimmedOwner.IsDimmed = true;
     }
     else
     {
         _dimmedOwner = null;
     }
 }
コード例 #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DpiAwarenessViewModel" /> class.
 /// </summary>
 public DpiAwarenessViewModel()
 {
     this.wnd = (DpiAwareWindow)App.Current.MainWindow;
     this.wnd.DpiChanged += OnWndDpiChanged;
     this.wnd.SizeChanged += OnWndSizeChanged;
 }
コード例 #5
0
ファイル: DpiAwareWindow.cs プロジェクト: gro-ove/actools
 private void UndimOwner() {
     if (_dimmedOwner != null) {
         _dimmedOwner.IsDimmed = false;
         _dimmedOwner = null;
     }
 }
コード例 #6
0
ファイル: EntryPoint.cs プロジェクト: gro-ove/actools
        public static void HandleSecondInstanceMessages(DpiAwareWindow window, Action<IEnumerable<string>> handler) {
            HwndSource hwnd = null;
            HwndSourceHook hook = (IntPtr handle, int message, IntPtr wParam, IntPtr lParam, ref bool handled) => {
                if (message == SecondInstanceMessage) {
                    try {
                        handler(ReceiveSomeData());
                        window.BringToFront();
                    } catch (Exception e) {
                        Logging.Warning("Can’t handle message: " + e);
                    }
                }

                return IntPtr.Zero;
            };

            RoutedEventHandler[] handlers = { null, null };

            // loaded
            handlers[0] = (sender, args) => {
                window.Loaded -= handlers[0];

                try {
                    hwnd = HwndSource.FromHwnd(new WindowInteropHelper(window).Handle);
                    if (hwnd == null) {
                        Logging.Warning("Can’t add one-instance hook: HwndSource is null");
                        return;
                    }

                    hwnd.AddHook(hook);
                    window.Unloaded += handlers[1];
                } catch (Exception e) {
                    Logging.Warning("Can’t add one-instance hook: " + e);
                    hook = null;
                }
            };
            
            // unloaded
            handlers[1] = (sender, args) => {
                window.Unloaded -= handlers[1];

                try {
                    hwnd.RemoveHook(hook);
                } catch (Exception e) {
                    Logging.Warning("Can’t remove one-instance hook: " + e);
                    hook = null;
                }
            };

            if (!window.IsLoaded) {
                window.Loaded += handlers[0];
            } else {
                handlers[0](null, null);
            }
        }
コード例 #7
0
 public void SetParent(DpiAwareWindow parent)
 {
     _parent = parent;
 }