public static AppWindow GetAppWindowForCurrentWindow(this Window window)
        {
            var hWnd  = WindowNative.GetWindowHandle(window);
            var winId = Win32Interop.GetWindowIdFromWindow(hWnd);

            return(AppWindow.GetFromWindowId(winId));
        }
Example #2
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;
        }
        private AppWindow GetAppWindowForCurrentWindow()
        {
            IntPtr   hWnd  = WindowNative.GetWindowHandle(this);
            WindowId wndId = Win32Interop.GetWindowIdFromWindow(hWnd);

            return(AppWindow.GetFromWindowId(wndId));
        }
Example #4
0
        public static IntPtr GetWindowHandle(this UI.Xaml.Window platformWindow)
        {
            var hwnd = WindowNative.GetWindowHandle(platformWindow);

            if (hwnd == IntPtr.Zero)
            {
                throw new NullReferenceException("The Window Handle is null.");
            }

            return(hwnd);
        }
Example #5
0
        /// <summary>
        /// Invoked when the application is launched normally by the end user.  Other entry points
        /// will be used such as when the application is launched to open a specific file.
        /// </summary>
        /// <param name="args">Details about the launch request and process.</param>
        protected override async void OnLaunched(LaunchActivatedEventArgs args)
        {
            Window = new MainWindow();

            WindowId id = Win32Interop.GetWindowIdFromWindow(WindowNative.GetWindowHandle(Window));

            AppWindow = AppWindow.GetFromWindowId(id);

            AppWindow.TitleBar.ExtendsContentIntoTitleBar = true;

            await Task.Run(AppInitiating);

            Window.Navigate(typeof(Pages.CommonPage));

            Window.Activate();
        }
Example #6
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"));
        }
Example #7
0
        private double GetScaleAdjustment()
        {
            IntPtr      hWnd        = WindowNative.GetWindowHandle(this);
            WindowId    wndId       = Win32Interop.GetWindowIdFromWindow(hWnd);
            DisplayArea displayArea = DisplayArea.GetFromWindowId(wndId, DisplayAreaFallback.Primary);
            IntPtr      hMonitor    = Win32Interop.GetMonitorFromDisplayId(displayArea.DisplayId);

            // Get DPI.
            int result = GetDpiForMonitor(hMonitor, Monitor_DPI_Type.MDT_Default, out uint dpiX, out uint _);

            if (result != 0)
            {
                throw new Exception("Could not get DPI for monitor.");
            }

            uint scaleFactorPercent = (uint)(((long)dpiX * 100 + (96 >> 1)) / 96);

            return(scaleFactorPercent / 100.0);
        }