1 コミット
作成者 SHA1 メッセージ 日付
routersys b01ea9159a ポップアップウィンドウへのDWMテーマ自動適用機能の追加
IWindowThemeServiceインターフェースを新規作成し、Bind(Window)メソッドを定義しました。
WindowThemeServiceクラスを実装し、SourceInitializedおよびLoadedイベントにフックしてウィンドウ生成時に自動でテーマを適用するようにしました。
テーマ適用はWindows11以降のみを対象とし、DWM APIのDwmSetWindowAttributeを用いてキャプションバー・ボーダー・テキストの色をWPFのシステムカラーリソースから取得して設定しました。
WindowThemeRegistry静的クラスを導入し、Null Objectパターンにより未登録時でも安全に動作するNullWindowThemeServiceをデフォルト実装として保持するようにしました。
RegisterメソッドはInterlocked.Exchangeでスレッドセーフな差し替えを保証するようにしました。
PluginHostの初期化処理にてWindowThemeServiceをWindowThemeRegistryへ登録し、GenerationPopupView生成直後にWindowThemeRegistry.Bindを呼び出してポップアップウィンドウをテーマサービスに紐付けるようにしました。
2026-03-25 20:19:00 +09:00
4個のファイルの変更、80行の追加、0行の削除

検索条件に一致するファイルはありません

+8
ファイルの表示
@@ -0,0 +1,8 @@
using System.Windows;
namespace ProxyForge.Interfaces;
internal interface IWindowThemeService
{
void Bind(Window window);
}
+3
ファイルの表示
@@ -3,6 +3,7 @@ using ProxyForge.Core;
using ProxyForge.Detection;
using ProxyForge.Interfaces;
using ProxyForge.Memory;
using ProxyForge.Services;
using ProxyForge.Settings;
using ProxyForge.Streaming;
using ProxyForge.ViewModels;
@@ -60,6 +61,7 @@ internal sealed class PluginHost : IDisposable
var chunkAllocator = new ChunkAllocator(65536);
MfSession.AddRef();
WindowThemeRegistry.Register(new WindowThemeService());
IProxyEncoderFactory encoderFactory = new MfProxyEncoderFactory(
budget,
@@ -124,6 +126,7 @@ internal sealed class PluginHost : IDisposable
{
var vm = new GenerationPopupViewModel(CacheManager.ActiveGenerations);
_popupView = new GenerationPopupView(vm);
WindowThemeRegistry.Bind(_popupView);
var mainWindow = Application.Current?.MainWindow;
if (mainWindow is { IsLoaded: true })
+22
ファイルの表示
@@ -0,0 +1,22 @@
using ProxyForge.Interfaces;
using System.Windows;
namespace ProxyForge.Services;
internal static class WindowThemeRegistry
{
private static IWindowThemeService _service = NullWindowThemeService.Instance;
internal static void Register(IWindowThemeService service)
=> Interlocked.Exchange(ref _service, service ?? NullWindowThemeService.Instance);
internal static void Bind(Window window)
=> _service.Bind(window);
private sealed class NullWindowThemeService : IWindowThemeService
{
internal static readonly NullWindowThemeService Instance = new();
private NullWindowThemeService() { }
public void Bind(Window window) { }
}
}
+47
ファイルの表示
@@ -0,0 +1,47 @@
using ProxyForge.Interfaces;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Interop;
using System.Windows.Media;
namespace ProxyForge.Services;
internal sealed class WindowThemeService : IWindowThemeService
{
public void Bind(Window window)
{
if (window is null) return;
window.SourceInitialized += (_, _) => ApplyCurrentTheme(window);
window.Loaded += (_, _) => ApplyCurrentTheme(window);
}
private static void ApplyCurrentTheme(Window window)
{
if (!OperatingSystem.IsWindowsVersionAtLeast(10, 0, 22000)) return;
var hwnd = new WindowInteropHelper(window).Handle;
if (hwnd == nint.Zero) return;
var captionBrush = (window.TryFindResource(SystemColors.ControlBrushKey) as SolidColorBrush) ?? Brushes.White;
var textBrush = (window.TryFindResource(SystemColors.WindowTextBrushKey) as SolidColorBrush) ?? Brushes.Black;
SetDwmColor(hwnd, NativeMethods.DwmwaCaption, captionBrush.Color);
SetDwmColor(hwnd, NativeMethods.DwmwaBorder, captionBrush.Color);
SetDwmColor(hwnd, NativeMethods.DwmwaText, textBrush.Color);
}
private static void SetDwmColor(nint hwnd, uint attribute, Color color)
{
uint colorRef = color.R | ((uint)color.G << 8) | ((uint)color.B << 16);
NativeMethods.DwmSetWindowAttribute(hwnd, attribute, ref colorRef, sizeof(uint));
}
private static class NativeMethods
{
internal const uint DwmwaCaption = 35;
internal const uint DwmwaBorder = 34;
internal const uint DwmwaText = 36;
[DllImport("dwmapi.dll")]
internal static extern int DwmSetWindowAttribute(nint hwnd, uint dwAttribute, ref uint pvAttribute, uint cbAttribute);
}
}