@@ -8,23 +8,21 @@ 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 @"
1315using System;
1416using System.Runtime.InteropServices;
1517
1618public class Win32Utils {
1719 [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
18- public static extern int SendMessageTimeout(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam, int fuFlags, int uTimeout, out IntPtr lpdwResult);
20+ public static extern int SendMessageTimeout(IntPtr hWnd, int Msg, IntPtr wParam, string lParam, int fuFlags, int uTimeout, out IntPtr lpdwResult);
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