From 193b0ca35411e24f2f9b7200ceab3033ff69600c Mon Sep 17 00:00:00 2001
From: ScrubN <72096833+ScrubN@users.noreply.github.com>
Date: Sun, 15 Oct 2023 01:15:17 -0400
Subject: [PATCH] I promise this is the last time I touch the dark title bar
code
---
TwitchDownloaderWPF/Services/NativeFunctions.cs | 4 ++--
TwitchDownloaderWPF/Services/ThemeService.cs | 8 +++++++-
TwitchDownloaderWPF/TwitchDownloaderWPF.csproj | 1 +
3 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/TwitchDownloaderWPF/Services/NativeFunctions.cs b/TwitchDownloaderWPF/Services/NativeFunctions.cs
index 332fe2a5..d4a4e08d 100644
--- a/TwitchDownloaderWPF/Services/NativeFunctions.cs
+++ b/TwitchDownloaderWPF/Services/NativeFunctions.cs
@@ -5,9 +5,9 @@
namespace TwitchDownloaderWPF.Services
{
[SupportedOSPlatform("windows")]
- public static class NativeFunctions
+ public static unsafe class NativeFunctions
{
[DllImport("dwmapi.dll", EntryPoint = "DwmSetWindowAttribute", PreserveSig = true)]
- public static extern int SetWindowAttribute(IntPtr handle, int attribute, [In] ref int attributeValue, int attributeSize);
+ public static extern int SetWindowAttribute(IntPtr handle, int attribute, void* attributeValue, uint attributeSize);
}
}
\ No newline at end of file
diff --git a/TwitchDownloaderWPF/Services/ThemeService.cs b/TwitchDownloaderWPF/Services/ThemeService.cs
index a8c80d86..37708653 100644
--- a/TwitchDownloaderWPF/Services/ThemeService.cs
+++ b/TwitchDownloaderWPF/Services/ThemeService.cs
@@ -103,7 +103,13 @@ public void SetTitleBarTheme(WindowCollection windows)
foreach (Window window in windows)
{
var windowHandle = new WindowInteropHelper(window).Handle;
- NativeFunctions.SetWindowAttribute(windowHandle, darkTitleBarAttribute, ref shouldUseDarkTitleBar, sizeof(int));
+ if (windowHandle == IntPtr.Zero)
+ continue;
+
+ unsafe
+ {
+ _ = NativeFunctions.SetWindowAttribute(windowHandle, darkTitleBarAttribute, &shouldUseDarkTitleBar, sizeof(int));
+ }
}
Window wnd = new()
diff --git a/TwitchDownloaderWPF/TwitchDownloaderWPF.csproj b/TwitchDownloaderWPF/TwitchDownloaderWPF.csproj
index c2f05537..00e51d42 100644
--- a/TwitchDownloaderWPF/TwitchDownloaderWPF.csproj
+++ b/TwitchDownloaderWPF/TwitchDownloaderWPF.csproj
@@ -21,6 +21,7 @@
true
false
AnyCPU;x64
+ true