Ejemplo n.º 1
0
        private AppWindow GetAppWindowForCurrentWindow()
        {
            IntPtr   hWnd  = WindowNative.GetWindowHandle(this);
            WindowId wndId = Win32Interop.GetWindowIdFromWindow(hWnd);

            return(AppWindow.GetFromWindowId(wndId));
        }
        /// <summary>
        /// Gets the AppWindow from the Window.
        /// </summary>
        /// <param name="window"></param>
        /// <returns></returns>
        public static AppWindow GetAppWindow(this Window window)
        {
            IntPtr hWnd     = WinRT.Interop.WindowNative.GetWindowHandle(window);
            var    windowId = Microsoft.UI.Win32Interop.GetWindowIdFromWindow(hWnd);

            return(AppWindow.GetFromWindowId(windowId));
        }
Ejemplo n.º 3
0
        public static AppWindow GetAppWindowForCurrentWindow(this Window window)
        {
            var hWnd  = WindowNative.GetWindowHandle(window);
            var winId = Win32Interop.GetWindowIdFromWindow(hWnd);

            return(AppWindow.GetFromWindowId(winId));
        }
Ejemplo n.º 4
0
        protected override async void OnLaunched(LaunchActivatedEventArgs e)
        {
            await ApplicationDataMigration.Migrate();

            await DatabaseManager.Instance.InitializeDb();

            await SettingsViewModel.Instance.Load();

            await SearchResultsViewModel.Instance.Load();

            if (!Resources.ContainsKey("settings"))
            {
                Resources.Add("settings", Settings.Instance);
            }

            string[] args            = Environment.GetCommandLineArgs();
            string   launchArguments = args.Length >= 2 ? args[1] : null;

            mainWindow = new MainWindow(launchArguments);

            IntPtr    hWnd      = WindowNative.GetWindowHandle(mainWindow);
            WindowId  windowId  = Win32Interop.GetWindowIdFromWindow(hWnd);
            AppWindow appWindow = AppWindow.GetFromWindowId(windowId);

            mainWindow.Activate();

            appWindow.Closing += AppWindow_Closing;
        }
        /// <summary>
        /// Get's the <see cref="AppWindow"/> that is assigned to the <c>WinUI</c> <see cref="Window"/>
        /// </summary>
        /// <param name="window">Reference to a <c>WinUI</c> <see cref="Microsoft.UI.Xaml.Window"/></param>
        /// <returns></returns>
        public static AppWindow GetAppWindow(this Window window)
        {
            IntPtr hWnd  = window.GetHandle();
            var    winId = Win32Interop.GetWindowIdFromWindow(hWnd);

            return(AppWindow.GetFromWindowId(winId));
        }
Ejemplo n.º 6
0
        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);
            });
        }
Ejemplo n.º 7
0
        private static void ResizeWindow(Window window, int width, int height)
        {
            IntPtr    hWnd      = WinRT.Interop.WindowNative.GetWindowHandle(window);
            WindowId  windowId  = Win32Interop.GetWindowIdFromWindow(hWnd);
            AppWindow appWindow = AppWindow.GetFromWindowId(windowId);

            var size = new SizeInt32(width, height);

            appWindow.Resize(size);
        }
Ejemplo n.º 8
0
        public static AppWindow GetAppWindowFromWPFWindow(this Window wpfWindow)
        {
            // Get the HWND of the top level WPF window.
            var hwnd = new WindowInteropHelper(wpfWindow).EnsureHandle();

            // Get the WindowId from the HWND.
            WindowId windowId = Win32Interop.GetWindowIdFromWindow(hwnd);

            // Return AppWindow from the WindowId.
            return(AppWindow.GetFromWindowId(windowId));
        }
Ejemplo n.º 9
0
        public static AppWindow GetAppWindowFromWinformsWindow(this IWin32Window winformsWindow)
        {
            // Get the HWND of the top level WinForms window
            IntPtr hwnd = winformsWindow.Handle;

            // Get the WindowId from the HWND.
            WindowId windowId = Win32Interop.GetWindowIdFromWindow(hwnd);

            // Return an AppWindow from the WindowId.
            return(AppWindow.GetFromWindowId(windowId));
        }
Ejemplo n.º 10
0
        private void InitWindow()
        {
            IntPtr    hWnd      = WinRT.Interop.WindowNative.GetWindowHandle(this);
            WindowId  windowId  = Win32Interop.GetWindowIdFromWindow(hWnd);
            AppWindow appWindow = AppWindow.GetFromWindowId(windowId);
            var       size      = new Windows.Graphics.SizeInt32();

            size.Width  = 1280;
            size.Height = 960;
            appWindow.Resize(size);
            appWindow.SetIcon("icon.ico");
            this.Title = "LR(1)语义分析过程表";
        }
Ejemplo n.º 11
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);
            });
        }
Ejemplo n.º 12
0
        public MainWindow()
        {
            InitializeComponent();

            ExtendsContentIntoTitleBar = true;
            SetTitleBar(_appTitleBar);

            IntPtr   windowHandle = WinRT.Interop.WindowNative.GetWindowHandle(this);
            WindowId windowId     = Win32Interop.GetWindowIdFromWindow(windowHandle);
            var      appWindow    = AppWindow.GetFromWindowId(windowId);

            appWindow.SetIcon(Path.Combine(Package.Current.InstalledLocation.Path, "Icon.ico"));
            appWindow.Title = _appTitleTextBlock.Text;

            _rootFrame.Navigate(typeof(MainPage));
        }
Ejemplo n.º 13
0
        private void SetTitleBarColorsAndIcon()
        {
            IntPtr    hWnd      = WindowNative.GetWindowHandle(this);
            WindowId  windowId  = Win32Interop.GetWindowIdFromWindow(hWnd);
            AppWindow appWindow = AppWindow.GetFromWindowId(windowId);

            // Title bar customization is not supported on Windows 10
            if (AppWindowTitleBar.IsCustomizationSupported())
            {
                AppWindowTitleBar titleBar = appWindow.TitleBar;

                ResourceDictionary dictionary = null;

                switch (Settings.Instance.AppTheme)
                {
                case ElementTheme.Default:
                    dictionary = Application.Current.Resources;
                    break;

                case ElementTheme.Light:
                    dictionary = (ResourceDictionary)Application.Current.Resources.ThemeDictionaries["Light"];
                    break;

                case ElementTheme.Dark:
                    dictionary = (ResourceDictionary)Application.Current.Resources.ThemeDictionaries["Dark"];
                    break;
                }

                titleBar.BackgroundColor               = (Color?)dictionary["TitleBarBackgroundColor"];
                titleBar.ForegroundColor               = (Color?)dictionary["TitleBarForegroundColor"];
                titleBar.InactiveBackgroundColor       = (Color?)dictionary["TitleBarInactiveBackgroundColor"];
                titleBar.InactiveForegroundColor       = (Color?)dictionary["TitleBarInactiveForegroundColor"];
                titleBar.ButtonBackgroundColor         = (Color?)dictionary["TitleBarButtonBackgroundColor"];
                titleBar.ButtonHoverBackgroundColor    = (Color?)dictionary["TitleBarButtonHoverBackgroundColor"];
                titleBar.ButtonForegroundColor         = (Color?)dictionary["TitleBarButtonForegroundColor"];
                titleBar.ButtonHoverForegroundColor    = (Color?)dictionary["TitleBarButtonHoverForegroundColor"];
                titleBar.ButtonPressedBackgroundColor  = (Color?)dictionary["TitleBarButtonPressedBackgroundColor"];
                titleBar.ButtonPressedForegroundColor  = (Color?)dictionary["TitleBarButtonPressedForegroundColor"];
                titleBar.ButtonInactiveBackgroundColor = (Color?)dictionary["TitleBarButtonInactiveBackgroundColor"];
                titleBar.ButtonInactiveForegroundColor = (Color?)dictionary["TitleBarButtonInactiveForegroundColor"];
            }

            string applicationRoot = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);

            appWindow.SetIcon(Path.Combine(applicationRoot, @"Assets\Logo.ico"));
        }
Ejemplo n.º 14
0
        private void InitWindow()
        {
            IntPtr    hWnd      = WinRT.Interop.WindowNative.GetWindowHandle(this);
            WindowId  windowId  = Win32Interop.GetWindowIdFromWindow(hWnd);
            AppWindow appWindow = AppWindow.GetFromWindowId(windowId);
            var       size      = new Windows.Graphics.SizeInt32();

            size.Width  = 710;
            size.Height = 850;
            appWindow.Resize(size);
            appWindow.SetIcon("icon.ico");
            this.Title   = "C--文法产生式";
            this.Closed += (o, e) =>
            {
                MainWebView.Close();
            };
            LoadedWebview();
        }
Ejemplo n.º 15
0
        public App()
        {
            InitializeComponent();

            Microsoft.Maui.Handlers.WindowHandler.Mapper.AppendToMapping(nameof(IWindow), (handler, view) =>
            {
#if WINDOWS
                handler.PlatformView.Activate();

                IntPtr windowHandle = WinRT.Interop.WindowNative.GetWindowHandle(handler.PlatformView);
                AppWindow appWindow = AppWindow.GetFromWindowId(Win32Interop.GetWindowIdFromWindow(windowHandle));

                appWindow.Resize(new SizeInt32(WindowWidth, WindowHeight));
#endif
            });

            MainPage = new NavigationPage(new MainPage());
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Default the Window Icon to the icon stored in the .exe, if any.
        ///
        /// The Icon can be overriden by callers by calling SetIcon themselves.
        /// </summary>
        void SetIcon()
        {
            var processPath = Environment.ProcessPath;

            if (!string.IsNullOrEmpty(processPath))
            {
                var index = IntPtr.Zero;                 // 0 = first icon in resources
                _windowIcon = ExtractAssociatedIcon(IntPtr.Zero, processPath, ref index);
                if (_windowIcon != IntPtr.Zero)
                {
                    var appWindow = AppWindow.GetFromWindowId(Win32Interop.GetWindowIdFromWindow(WindowHandle));
                    if (appWindow is not null)
                    {
                        var iconId = Win32Interop.GetIconIdFromIcon(_windowIcon);
                        appWindow.SetIcon(iconId);
                    }
                }
            }
        }
Ejemplo n.º 17
0
        public static AppWindow?GetActiveAppWindow(this IWindowStateManager manager, bool throwOnNull)
        {
            var window = manager.GetActiveWindow();

            if (throwOnNull && window == null)
            {
                throw new NullReferenceException("The active Window can not be detected. Ensure that you have called Init in your Application class.");
            }

            if (window == null)
            {
                return(null);
            }

            var handle    = WinRT.Interop.WindowNative.GetWindowHandle(window);
            var windowId  = UI.Win32Interop.GetWindowIdFromWindow(handle);
            var appWindow = AppWindow.GetFromWindowId(windowId);

            return(appWindow);
        }
Ejemplo n.º 18
0
        public MainWindow()
        {
            this.InitializeComponent();
            IntPtr    hWnd      = WinRT.Interop.WindowNative.GetWindowHandle(this);
            WindowId  windowId  = Win32Interop.GetWindowIdFromWindow(hWnd);
            AppWindow appWindow = AppWindow.GetFromWindowId(windowId);
            var       size      = new Windows.Graphics.SizeInt32();

            size.Width  = 1280;
            size.Height = 960;
            appWindow.Resize(size);
            appWindow.SetIcon("icon.ico");

            this.Title          = "C--编译器";
            Lexcial.IsEnabled   = false;
            Syntactic.IsEnabled = false;
            Semantic.IsEnabled  = false;
            Mips.IsEnabled      = false;
            LoadedWebview();
            this.Closed += (o, e) =>
            {
                MainWebView.Close();
            };
        }
Ejemplo n.º 19
0
        public MainWindow(bool createHidden = false)
        {
            var bootTime = new System.Diagnostics.Stopwatch();

            bootTime.Start();

            ShellPage.SetElevationStatus(App.IsElevated);
            ShellPage.SetIsUserAnAdmin(App.IsUserAnAdmin);

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

            appWindow.SetIcon("icon.ico");

            var placement = Utils.DeserializePlacementOrDefault(hWnd);

            if (createHidden)
            {
                placement.ShowCmd = NativeMethods.SW_HIDE;
            }

            NativeMethods.SetWindowPlacement(hWnd, ref placement);

            ResourceLoader loader = ResourceLoader.GetForViewIndependentUse();

            Title = loader.GetString("SettingsWindow_Title");

            // send IPC Message
            ShellPage.SetDefaultSndMessageCallback(msg =>
            {
                // IPC Manager is null when launching runner directly
                App.GetTwoWayIPCManager()?.Send(msg);
            });

            // send IPC Message
            ShellPage.SetRestartAdminSndMessageCallback(msg =>
            {
                App.GetTwoWayIPCManager()?.Send(msg);
                Environment.Exit(0); // close application
            });

            // send IPC Message
            ShellPage.SetCheckForUpdatesMessageCallback(msg =>
            {
                App.GetTwoWayIPCManager()?.Send(msg);
            });

            // open oobe
            ShellPage.SetOpenOobeCallback(() =>
            {
                if (App.GetOobeWindow() == null)
                {
                    App.SetOobeWindow(new OobeWindow(Microsoft.PowerToys.Settings.UI.OOBE.Enums.PowerToysModules.Overview));
                }

                App.GetOobeWindow().Activate();
            });

            this.InitializeComponent();

            // receive IPC Message
            App.IPCMessageReceivedCallback = (string msg) =>
            {
                if (ShellPage.ShellHandler.IPCResponseHandleList != null)
                {
                    var success = JsonObject.TryParse(msg, out JsonObject json);
                    if (success)
                    {
                        foreach (Action <JsonObject> handle in ShellPage.ShellHandler.IPCResponseHandleList)
                        {
                            handle(json);
                        }
                    }
                    else
                    {
                        Logger.LogError("Failed to parse JSON from IPC message.");
                    }
                }
            };

            bootTime.Stop();

            PowerToysTelemetry.Log.WriteEvent(new SettingsBootEvent()
            {
                BootTimeMs = bootTime.ElapsedMilliseconds
            });
        }
Ejemplo n.º 20
0
        private static AppWindow GetAppWindowFromWindowHandle(IntPtr windowHandle)
        {
            WindowId windowId = Win32Interop.GetWindowIdFromWindow(windowHandle);

            return(AppWindow.GetFromWindowId(windowId));
        }