From 0b4e2e023c2cc567a227237a98828a54e54615d8 Mon Sep 17 00:00:00 2001 From: Wickedness Date: Tue, 9 Jun 2026 13:57:26 +0900 Subject: [PATCH] Apply TornadoAce icon to WinUI window --- TornadoAce_CJOnStyle/App.xaml.cs | 25 +++++++++++++++++++ .../TornadoAce_CJOnStyle.csproj | 4 ++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/TornadoAce_CJOnStyle/App.xaml.cs b/TornadoAce_CJOnStyle/App.xaml.cs index 99b9ab8..7ffbbb8 100644 --- a/TornadoAce_CJOnStyle/App.xaml.cs +++ b/TornadoAce_CJOnStyle/App.xaml.cs @@ -1,3 +1,8 @@ +using Microsoft.UI.Windowing; +using System; +using System.IO; +using WinRT.Interop; + namespace TornadoAce_CJOnStyle { /// @@ -28,6 +33,8 @@ namespace TornadoAce_CJOnStyle Title = "TornadoAce CJ OnStyle CG Automation" }; + ApplyWindowIcon(window); + if (window.Content is not Frame rootFrame) { rootFrame = new Frame(); @@ -39,6 +46,24 @@ namespace TornadoAce_CJOnStyle window.Activate(); } + private static void ApplyWindowIcon(Window targetWindow) + { + var iconPath = Path.Combine(AppContext.BaseDirectory, "Assets", "AppIcon.ico"); + if (!File.Exists(iconPath)) + { + return; + } + + var windowHandle = WindowNative.GetWindowHandle(targetWindow); + if (windowHandle == IntPtr.Zero) + { + return; + } + + var windowId = Microsoft.UI.Win32Interop.GetWindowIdFromWindow(windowHandle); + AppWindow.GetFromWindowId(windowId)?.SetIcon(iconPath); + } + /// /// Invoked when Navigation to a certain page fails /// diff --git a/TornadoAce_CJOnStyle/TornadoAce_CJOnStyle.csproj b/TornadoAce_CJOnStyle/TornadoAce_CJOnStyle.csproj index 22d23ea..d198ba4 100644 --- a/TornadoAce_CJOnStyle/TornadoAce_CJOnStyle.csproj +++ b/TornadoAce_CJOnStyle/TornadoAce_CJOnStyle.csproj @@ -30,7 +30,9 @@ - + + PreserveNewest +