private AppWindow GetAppWindowForCurrentWindow() { IntPtr hWnd = WindowNative.GetWindowHandle(this); WindowId wndId = Win32Interop.GetWindowIdFromWindow(hWnd); return(AppWindow.GetFromWindowId(wndId)); }
/// <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)); }
public static AppWindow GetAppWindowForCurrentWindow(this Window window) { var hWnd = WindowNative.GetWindowHandle(window); var winId = Win32Interop.GetWindowIdFromWindow(hWnd); return(AppWindow.GetFromWindowId(winId)); }
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; }
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); }); }
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); }
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)); }
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)); }
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)语义分析过程表"; }
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); }); }
/// <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(); }
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)); }
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")); }
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(); }
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()); }
/// <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); } } } }
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); }
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(); }; }
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 }); }
private static AppWindow GetAppWindowFromWindowHandle(IntPtr windowHandle) { WindowId windowId = Win32Interop.GetWindowIdFromWindow(windowHandle); return(AppWindow.GetFromWindowId(windowId)); }