From e63f408fbbdf6186c44b42909b37f3a27ff9b61e Mon Sep 17 00:00:00 2001 From: Francesco Santone <79326795+KrakenByte27@users.noreply.github.com> Date: Wed, 26 Feb 2025 14:46:06 +0100 Subject: [PATCH 1/3] Update ChangeWindowsSystemTheme.ps1 Added script code for Windows theme auto-refresh --- stable/ChangeWindowsSystemTheme.ps1 | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/stable/ChangeWindowsSystemTheme.ps1 b/stable/ChangeWindowsSystemTheme.ps1 index 436db23..2d78e52 100644 --- a/stable/ChangeWindowsSystemTheme.ps1 +++ b/stable/ChangeWindowsSystemTheme.ps1 @@ -7,3 +7,24 @@ if (Test-Path $registryPath) { New-ItemProperty -Path $registryPath -Name "SystemUsesLightTheme" -Value $dwordValue -PropertyType DWORD -Force | Out-Null } + +# Call Windows theme auto-refresh +Add-Type -TypeDefinition @" +using System; +using System.Runtime.InteropServices; + +public class Win32Utils { + [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] + public static extern int SendMessageTimeout(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam, int fuFlags, int uTimeout, out IntPtr lpdwResult); +} +"@ -PassThru + +$HWND_BROADCAST = [IntPtr]::Zero -bor 0xFFFF +$WM_SETTINGCHANGE = 0x1A +$SPI_SETCLIENTAREAANIMATION = 0x1043 + +$param = [System.Runtime.InteropServices.Marshal]::StringToHGlobalUni("ImmersiveColorSet") + +$null = [Win32Utils]::SendMessageTimeout($HWND_BROADCAST, $WM_SETTINGCHANGE, [IntPtr]::Zero, $param, 2, 5000, [ref]([IntPtr]::Zero)) + +[System.Runtime.InteropServices.Marshal]::FreeHGlobal($param) From 53e2b4f0b3f7269da632e61814c86bf271a231af Mon Sep 17 00:00:00 2001 From: Francesco Santone <79326795+KrakenByte27@users.noreply.github.com> Date: Wed, 26 Feb 2025 14:48:35 +0100 Subject: [PATCH 2/3] Added auto-refresh for ChangeWindowsAppTheme.ps1 Added script code for Windows theme auto-refresh --- stable/ChangeWindowsAppTheme.ps1 | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/stable/ChangeWindowsAppTheme.ps1 b/stable/ChangeWindowsAppTheme.ps1 index 719f979..db1fad4 100644 --- a/stable/ChangeWindowsAppTheme.ps1 +++ b/stable/ChangeWindowsAppTheme.ps1 @@ -7,3 +7,24 @@ if (Test-Path $registryPath) { New-ItemProperty -Path $registryPath -Name "AppsUseLightTheme" -Value $dwordValue -PropertyType DWORD -Force | Out-Null } + +# Call Windows theme refresh +Add-Type -TypeDefinition @" +using System; +using System.Runtime.InteropServices; + +public class Win32Utils { + [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] + public static extern int SendMessageTimeout(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam, int fuFlags, int uTimeout, out IntPtr lpdwResult); +} +"@ -PassThru + +$HWND_BROADCAST = [IntPtr]::Zero -bor 0xFFFF +$WM_SETTINGCHANGE = 0x1A +$SPI_SETCLIENTAREAANIMATION = 0x1043 + +$param = [System.Runtime.InteropServices.Marshal]::StringToHGlobalUni("ImmersiveColorSet") + +$null = [Win32Utils]::SendMessageTimeout($HWND_BROADCAST, $WM_SETTINGCHANGE, [IntPtr]::Zero, $param, 2, 5000, [ref]([IntPtr]::Zero)) + +[System.Runtime.InteropServices.Marshal]::FreeHGlobal($param) From 73bdd4b2983a798644d0ce12736b8d965a861be2 Mon Sep 17 00:00:00 2001 From: Timothy Johnson Date: Thu, 6 Mar 2025 07:17:29 -0500 Subject: [PATCH 3/3] Refresh theme is only needed on Win11 --- stable/ChangeWindowsAppTheme.ps1 | 22 ++++++++++------------ stable/ChangeWindowsSystemTheme.ps1 | 22 ++++++++++------------ 2 files changed, 20 insertions(+), 24 deletions(-) diff --git a/stable/ChangeWindowsAppTheme.ps1 b/stable/ChangeWindowsAppTheme.ps1 index db1fad4..0b2dc52 100644 --- a/stable/ChangeWindowsAppTheme.ps1 +++ b/stable/ChangeWindowsAppTheme.ps1 @@ -8,23 +8,21 @@ if (Test-Path $registryPath) New-ItemProperty -Path $registryPath -Name "AppsUseLightTheme" -Value $dwordValue -PropertyType DWORD -Force | Out-Null } -# Call Windows theme refresh -Add-Type -TypeDefinition @" +if ([System.Environment]::OSVersion.Version.Build -ge 22000) +{ + # Call Windows theme refresh + Add-Type -TypeDefinition @" using System; using System.Runtime.InteropServices; public class Win32Utils { [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] - public static extern int SendMessageTimeout(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam, int fuFlags, int uTimeout, out IntPtr lpdwResult); + public static extern int SendMessageTimeout(IntPtr hWnd, int Msg, IntPtr wParam, string lParam, int fuFlags, int uTimeout, out IntPtr lpdwResult); } "@ -PassThru -$HWND_BROADCAST = [IntPtr]::Zero -bor 0xFFFF -$WM_SETTINGCHANGE = 0x1A -$SPI_SETCLIENTAREAANIMATION = 0x1043 - -$param = [System.Runtime.InteropServices.Marshal]::StringToHGlobalUni("ImmersiveColorSet") - -$null = [Win32Utils]::SendMessageTimeout($HWND_BROADCAST, $WM_SETTINGCHANGE, [IntPtr]::Zero, $param, 2, 5000, [ref]([IntPtr]::Zero)) - -[System.Runtime.InteropServices.Marshal]::FreeHGlobal($param) + $HWND_BROADCAST = [IntPtr]0xFFFF + $WM_SETTINGCHANGE = 0x1A + $SMTO_ABORTIFHUNG = 0x2 + [Win32Utils]::SendMessageTimeout($HWND_BROADCAST, $WM_SETTINGCHANGE, [IntPtr]::Zero, "ImmersiveColorSet", $SMTO_ABORTIFHUNG, 5000, [ref]([IntPtr]::Zero)) +} diff --git a/stable/ChangeWindowsSystemTheme.ps1 b/stable/ChangeWindowsSystemTheme.ps1 index 2d78e52..b15f0fe 100644 --- a/stable/ChangeWindowsSystemTheme.ps1 +++ b/stable/ChangeWindowsSystemTheme.ps1 @@ -8,23 +8,21 @@ if (Test-Path $registryPath) New-ItemProperty -Path $registryPath -Name "SystemUsesLightTheme" -Value $dwordValue -PropertyType DWORD -Force | Out-Null } -# Call Windows theme auto-refresh -Add-Type -TypeDefinition @" +if ([System.Environment]::OSVersion.Version.Build -ge 22000) +{ + # Call Windows theme refresh + Add-Type -TypeDefinition @" using System; using System.Runtime.InteropServices; public class Win32Utils { [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] - public static extern int SendMessageTimeout(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam, int fuFlags, int uTimeout, out IntPtr lpdwResult); + public static extern int SendMessageTimeout(IntPtr hWnd, int Msg, IntPtr wParam, string lParam, int fuFlags, int uTimeout, out IntPtr lpdwResult); } "@ -PassThru -$HWND_BROADCAST = [IntPtr]::Zero -bor 0xFFFF -$WM_SETTINGCHANGE = 0x1A -$SPI_SETCLIENTAREAANIMATION = 0x1043 - -$param = [System.Runtime.InteropServices.Marshal]::StringToHGlobalUni("ImmersiveColorSet") - -$null = [Win32Utils]::SendMessageTimeout($HWND_BROADCAST, $WM_SETTINGCHANGE, [IntPtr]::Zero, $param, 2, 5000, [ref]([IntPtr]::Zero)) - -[System.Runtime.InteropServices.Marshal]::FreeHGlobal($param) + $HWND_BROADCAST = [IntPtr]0xFFFF + $WM_SETTINGCHANGE = 0x1A + $SMTO_ABORTIFHUNG = 0x2 + [Win32Utils]::SendMessageTimeout($HWND_BROADCAST, $WM_SETTINGCHANGE, [IntPtr]::Zero, "ImmersiveColorSet", $SMTO_ABORTIFHUNG, 5000, [ref]([IntPtr]::Zero)) +}