コード例 #1
0
        private void ChangeWindowStyle(object sender, RoutedEventArgs e)
        {
            if (_mainAppWindow != null)
            {
                OverlappedPresenter customOverlappedPresenter;

                switch (sender.As <Button>().Name)
                {
                case "MainWindowBtn":
                    customOverlappedPresenter = OverlappedPresenter.Create();
                    break;

                case "ContextMenuBtn":
                    customOverlappedPresenter = OverlappedPresenter.CreateForContextMenu();
                    break;

                case "DialogWindowBtn":
                    customOverlappedPresenter = OverlappedPresenter.CreateForDialog();
                    break;

                case "ToolWindowBtn":
                    customOverlappedPresenter = OverlappedPresenter.CreateForToolWindow();
                    break;

                default:
                    // Something else called this method, we can't handle that so exit the method
                    return;
                }

                _mainAppWindow.SetPresenter(customOverlappedPresenter);
            }
        }
コード例 #2
0
ファイル: OobeWindow.xaml.cs プロジェクト: royvou/PowerToys
        public OobeWindow(PowerToysModules initialModule)
        {
            this.InitializeComponent();

            // Set window icon
            _hWnd      = WinRT.Interop.WindowNative.GetWindowHandle(this);
            _windowId  = Win32Interop.GetWindowIdFromWindow(_hWnd);
            _appWindow = AppWindow.GetFromWindowId(_windowId);
            _appWindow.SetIcon("icon.ico");

            OverlappedPresenter presenter = _appWindow.Presenter as OverlappedPresenter;

            presenter.IsResizable   = false;
            presenter.IsMinimizable = false;
            presenter.IsMaximizable = false;

            var dpi = NativeMethods.GetDpiForWindow(_hWnd);

            _currentDPI = dpi;
            float scalingFactor = (float)dpi / DefaultDPI;
            int   width         = (int)(ExpectedWidth * scalingFactor);
            int   height        = (int)(ExpectedHeight * scalingFactor);

            SizeInt32 size;

            size.Width  = width;
            size.Height = height;
            _appWindow.Resize(size);

            this.initialModule = initialModule;

            this.SizeChanged += OobeWindow_SizeChanged;

            ResourceLoader loader = ResourceLoader.GetForViewIndependentUse();

            Title = loader.GetString("OobeWindow_Title");

            if (shellPage != null)
            {
                shellPage.NavigateToModule(this.initialModule);
            }

            OobeShellPage.SetRunSharedEventCallback(() =>
            {
                return(Constants.PowerLauncherSharedEvent());
            });

            OobeShellPage.SetColorPickerSharedEventCallback(() =>
            {
                return(Constants.ShowColorPickerSharedEvent());
            });

            OobeShellPage.SetOpenMainWindowCallback((Type type) =>
            {
                App.OpenSettingsWindow(type);
            });
        }
コード例 #3
0
        public OobeWindow(PowerToysModules initialModule)
        {
            this.InitializeComponent();

            // Set window icon
            var       hWnd      = WinRT.Interop.WindowNative.GetWindowHandle(this);
            WindowId  windowId  = Win32Interop.GetWindowIdFromWindow(hWnd);
            AppWindow appWindow = AppWindow.GetFromWindowId(windowId);

            appWindow.SetIcon("icon.ico");

            OverlappedPresenter presenter = appWindow.Presenter as OverlappedPresenter;

            presenter.IsResizable   = false;
            presenter.IsMinimizable = false;
            presenter.IsMaximizable = false;

            SizeInt32 size;

            size.Width  = 1650;
            size.Height = 1050;
            appWindow.Resize(size);

            this.initialModule = initialModule;

            ResourceLoader loader = ResourceLoader.GetForViewIndependentUse();

            Title = loader.GetString("OobeWindow_Title");

            if (shellPage != null)
            {
                shellPage.NavigateToModule(this.initialModule);
            }

            OobeShellPage.SetRunSharedEventCallback(() =>
            {
                return(Constants.PowerLauncherSharedEvent());
            });

            OobeShellPage.SetColorPickerSharedEventCallback(() =>
            {
                return(Constants.ShowColorPickerSharedEvent());
            });

            OobeShellPage.SetOpenMainWindowCallback((Type type) =>
            {
                App.OpenSettingsWindow(type);
            });
        }
コード例 #4
0
        // Change the properties of the window based on which switch was toggled
        private void ChangeConfiguration(object sender, RoutedEventArgs e)
        {
            if (_mainAppWindow != null)
            {
                OverlappedPresenter overlappedPresenter = null;
                if (_mainAppWindow.Presenter.Kind == AppWindowPresenterKind.Overlapped)
                {
                    overlappedPresenter = _mainAppWindow.Presenter.As <OverlappedPresenter>();
                }

                switch (sender.As <Button>().Name)
                {
                case "FrameToggle":
                    if (overlappedPresenter.HasBorder && overlappedPresenter.HasTitleBar)
                    {
                        FrameToggle.Content = "Has No Frame";
                    }
                    else
                    {
                        FrameToggle.Content = "Has Frame";
                    }
                    overlappedPresenter.SetBorderAndTitleBar(!overlappedPresenter.HasBorder, !overlappedPresenter.HasTitleBar);
                    break;

                case "TitleBarToggle":
                    if (overlappedPresenter.HasBorder && overlappedPresenter.HasTitleBar)
                    {
                        TitleBarToggle.Content = "Has No Title Bar";
                    }
                    else
                    {
                        TitleBarToggle.Content = "Has Title Bar";
                    }
                    overlappedPresenter.SetBorderAndTitleBar(!overlappedPresenter.HasBorder, !overlappedPresenter.HasTitleBar);
                    break;

                case "AlwaysOnTopToggle":
                    if (overlappedPresenter.IsAlwaysOnTop)
                    {
                        AlwaysOnTopToggle.Content = "Is not Always on Top";
                    }
                    else
                    {
                        AlwaysOnTopToggle.Content = "Is Always on Top";
                    }
                    overlappedPresenter.IsAlwaysOnTop = !overlappedPresenter.IsAlwaysOnTop;
                    break;

                case "MaxToggle":
                    if (overlappedPresenter.IsMaximizable)
                    {
                        MaxToggle.Content = "Is not Maximizable";
                    }
                    else
                    {
                        MaxToggle.Content = "Is Maximizable";
                    }
                    overlappedPresenter.IsMaximizable = !overlappedPresenter.IsMaximizable;
                    break;

                case "MinToggle":
                    if (overlappedPresenter.IsMinimizable)
                    {
                        MinToggle.Content = "Is not Minimizable";
                    }
                    else
                    {
                        MinToggle.Content = "Is Minimizable";
                    }
                    overlappedPresenter.IsMinimizable = !overlappedPresenter.IsMinimizable;
                    break;

                case "ResizableToggle":
                    if (overlappedPresenter.IsResizable)
                    {
                        ResizableToggle.Content = "Is not Resizable";
                    }
                    else
                    {
                        ResizableToggle.Content = "Is Resizable";
                    }
                    overlappedPresenter.IsResizable = !overlappedPresenter.IsResizable;
                    break;

                case "InUxToggle":
                    if (_mainAppWindow.IsShownInSwitchers)
                    {
                        InUxToggle.Content = "Is not Shown in UX";
                    }
                    else
                    {
                        InUxToggle.Content = "Is Shown in UX";
                    }
                    _mainAppWindow.IsShownInSwitchers = !_mainAppWindow.IsShownInSwitchers;
                    break;

                default:
                    // Something else called this method, we can't handle that so exit the method
                    return;
                }
            }
        }