Skip to content

Commit fcc940b

Browse files
committed
Refresh theme is only needed on Win11
1 parent f6463fc commit fcc940b

File tree

2 files changed

+18
-22
lines changed

2 files changed

+18
-22
lines changed

stable/ChangeWindowsAppTheme.ps1

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ if (Test-Path $registryPath)
88
New-ItemProperty -Path $registryPath -Name "AppsUseLightTheme" -Value $dwordValue -PropertyType DWORD -Force | Out-Null
99
}
1010

11-
# Call Windows theme refresh
12-
Add-Type -TypeDefinition @"
11+
if ([System.Environment]::OSVersion.Version.Build -ge 22000)
12+
{
13+
# Call Windows theme refresh
14+
Add-Type -TypeDefinition @"
1315
using System;
1416
using System.Runtime.InteropServices;
1517
@@ -19,12 +21,8 @@ public class Win32Utils {
1921
}
2022
"@ -PassThru
2123

22-
$HWND_BROADCAST = [IntPtr]::Zero -bor 0xFFFF
23-
$WM_SETTINGCHANGE = 0x1A
24-
$SPI_SETCLIENTAREAANIMATION = 0x1043
25-
26-
$param = [System.Runtime.InteropServices.Marshal]::StringToHGlobalUni("ImmersiveColorSet")
27-
28-
$null = [Win32Utils]::SendMessageTimeout($HWND_BROADCAST, $WM_SETTINGCHANGE, [IntPtr]::Zero, $param, 2, 5000, [ref]([IntPtr]::Zero))
29-
30-
[System.Runtime.InteropServices.Marshal]::FreeHGlobal($param)
24+
$HWND_BROADCAST = [IntPtr]0xFFFF
25+
$WM_SETTINGCHANGE = 0x1A
26+
$SMTO_ABORTIFHUNG = 0x2
27+
[Win32Utils]::SendMessageTimeout($HWND_BROADCAST, $WM_SETTINGCHANGE, [IntPtr]::Zero, "ImmersiveColorSet", $SMTO_ABORTIFHUNG, 5000, [ref]([IntPtr]::Zero))
28+
}

stable/ChangeWindowsSystemTheme.ps1

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ if (Test-Path $registryPath)
88
New-ItemProperty -Path $registryPath -Name "SystemUsesLightTheme" -Value $dwordValue -PropertyType DWORD -Force | Out-Null
99
}
1010

11-
# Call Windows theme auto-refresh
12-
Add-Type -TypeDefinition @"
11+
if ([System.Environment]::OSVersion.Version.Build -ge 22000)
12+
{
13+
# Call Windows theme refresh
14+
Add-Type -TypeDefinition @"
1315
using System;
1416
using System.Runtime.InteropServices;
1517
@@ -19,12 +21,8 @@ public class Win32Utils {
1921
}
2022
"@ -PassThru
2123

22-
$HWND_BROADCAST = [IntPtr]::Zero -bor 0xFFFF
23-
$WM_SETTINGCHANGE = 0x1A
24-
$SPI_SETCLIENTAREAANIMATION = 0x1043
25-
26-
$param = [System.Runtime.InteropServices.Marshal]::StringToHGlobalUni("ImmersiveColorSet")
27-
28-
$null = [Win32Utils]::SendMessageTimeout($HWND_BROADCAST, $WM_SETTINGCHANGE, [IntPtr]::Zero, $param, 2, 5000, [ref]([IntPtr]::Zero))
29-
30-
[System.Runtime.InteropServices.Marshal]::FreeHGlobal($param)
24+
$HWND_BROADCAST = [IntPtr]0xFFFF
25+
$WM_SETTINGCHANGE = 0x1A
26+
$SMTO_ABORTIFHUNG = 0x2
27+
[Win32Utils]::SendMessageTimeout($HWND_BROADCAST, $WM_SETTINGCHANGE, [IntPtr]::Zero, "ImmersiveColorSet", $SMTO_ABORTIFHUNG, 5000, [ref]([IntPtr]::Zero))
28+
}

0 commit comments

Comments
 (0)