Skip to content

Commit

Permalink
Refresh theme is only needed on Win11
Browse files Browse the repository at this point in the history
  • Loading branch information
t1m0thyj committed Mar 6, 2025
1 parent f6463fc commit 73bdd4b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 24 deletions.
22 changes: 10 additions & 12 deletions stable/ChangeWindowsAppTheme.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
22 changes: 10 additions & 12 deletions stable/ChangeWindowsSystemTheme.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

0 comments on commit 73bdd4b

Please sign in to comment.