Apps which do this call it in a Thread or a Timer to refresh it
(like for example : https://github.com/WorkingRobot/WallpaperVisualizer/blob/9ccd923ca4379d6f4b1dc40755267ca7e85ae25c/WallpaperVisualizer/WallpaperVisualizer.cs#L53)
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi, I am encountering an issue with the taskbar color on Windows. When I change the taskbar color using the SetWindowCompositionAttribute
method, the color initially changes as expected. However, as soon as I click the 'Start' button, the taskbar color reverts to the default color specified by the Windows settings.
Steps to Reproduce:
SetWindowCompositionAttribute
.Expected Behavior: The taskbar color should remain as set by SetWindowCompositionAttribute
, even after interacting with the 'Start' button.
Actual Behavior: The taskbar color reverts to the default Windows settings when the 'Start' button is clicked.
Code Sample:
public static void SetTaskbarColor(Color color)
{
var accentPolicy = default(User32Interop.AccentPolicy);
accentPolicy.Color = color.ToAbgr();
accentPolicy.AccentState = 2;
accentPolicy.Flags = 2;
var data = default(User32Interop.Windowcompositionattribdata);
data.Attribute = User32Interop.WindowCompositionAttribute.WcaAccentPolicy;
data.SizeOfData = Marshal.SizeOf(typeof(User32Interop.AccentPolicy));
data.Data = Marshal.AllocHGlobal(data.SizeOfData);
Marshal.StructureToPtr(accentPolicy, data.Data, false);
var taskbarHandle = User32Interop.FindWindow("Shell_TrayWnd", null);
var secondaryTaskbarHandle = User32Interop.FindWindow("Shell_SecondaryTrayWnd", null);
if (taskbarHandle != nint.Zero)
{
User32Interop.SetWindowCompositionAttribute(taskbarHandle, ref data);
}
if (secondaryTaskbarHandle != nint.Zero)
{
User32Interop.SetWindowCompositionAttribute(secondaryTaskbarHandle, ref data);
}
Marshal.FreeHGlobal(data.Data);
}
Apps which do this call it in a Thread or a Timer to refresh it
(like for example : https://github.com/WorkingRobot/WallpaperVisualizer/blob/9ccd923ca4379d6f4b1dc40755267ca7e85ae25c/WallpaperVisualizer/WallpaperVisualizer.cs#L53)