Esempio n. 1
0
 protected override void OnDpiChanged(DpiScale oldDpi, DpiScale newDpi)
 {
     if (CurrentContainedWindow != null)
     {
         ConsoleFunctions.SendDpiChangedMessage(CurrentContainedWindowHandle, (int)newDpi.PixelsPerInchX);
         CurrentContainedWindow.Dpi = (int)newDpi.PixelsPerInchX;
     }
     base.OnDpiChanged(oldDpi, newDpi);
 }
Esempio n. 2
0
        private async Task ContainTargetWindow(HostedWindowItem item)
        {
            var target = item.WindowHandle;

            MyHost host;

            if ((App.Current as App).TargetWindowHosts.ContainsKey(target))
            {
                host = (App.Current as App).TargetWindowHosts[target];
            }
            else
            {
                host = new MyHost(target);
                (App.Current as App).TargetWindowHosts[target] = host;
            }

            if (host.Parent == null)
            {
                WindowContainer.Child = host;
            }
            else if (host.Parent != null && host.Parent != WindowContainer)
            {
                MessageBox.Show("ContainTargetWindow failed. The host has another parent.");
                return;
            }

            // TODO: Try to make it faster on console launch. But how?
            var dpi = VisualTreeHelper.GetDpi(this);

            if (item.Dpi != dpi.PixelsPerInchX)
            {
                ConsoleFunctions.SendDpiChangedMessage(target, (int)dpi.PixelsPerInchX);
                item.Dpi = dpi.PixelsPerInchX;
            }

            await Task.Delay(10);

            int style    = Win32Functions.GetWindowLongPtr(target, Win32Functions.GWL_STYLE).ToInt32();
            int newStyle = style & ~(Win32Functions.WS_CHILD);

            Win32Functions.SetWindowLongPtr(new HandleRef(this, target), Win32Functions.GWL_STYLE, new IntPtr(newStyle));

            await Task.Delay(10);

            MaximizeWindow(target, Win32.Enums.ShowWindowCommands.Normal);
            Win32Functions.SetForegroundWindow(target);
        }