Get the Active Color of Windows 8 Automatic Color Theme

How to get title bar color of WPF window in Windows 8.1?

I found a solution. Actually, the basic point has been already discussed.

  • Get the active color of Windows 8 automatic color theme
  • Changing Windows Aero Color

The sequence will be:

  1. Get parameters by DwmGetColorizationParameters function (undocumented API).
  2. Convert colorizationColor parameter to Color ignoring alpha channel.
  3. Prepare base gray color (R=217, G=217, B=217).
  4. Blend the two colors using colorizationColorBalance parameter which corresponds to "Color Intensity".

So, my code is as follows:

public static Color? GetChromeColor()
{
bool isEnabled;
var hr1 = DwmIsCompositionEnabled(out isEnabled);
if ((hr1 != 0) || !isEnabled) // 0 means S_OK.
return null;

DWMCOLORIZATIONPARAMS parameters;
try
{
// This API is undocumented and so may become unusable in future versions of OSes.
var hr2 = DwmGetColorizationParameters(out parameters);
if (hr2 != 0) // 0 means S_OK.
return null;
}
catch
{
return null;
}

// Convert colorization color parameter to Color ignoring alpha channel.
var targetColor = Color.FromRgb(
(byte)(parameters.colorizationColor >> 16),
(byte)(parameters.colorizationColor >> 8),
(byte)parameters.colorizationColor);

// Prepare base gray color.
var baseColor = Color.FromRgb(217, 217, 217);

// Blend the two colors using colorization color balance parameter.
return BlendColor(targetColor, baseColor, (double)(100 - parameters.colorizationColorBalance));
}

private static Color BlendColor(Color color1, Color color2, double color2Perc)
{
if ((color2Perc < 0) || (100 < color2Perc))
throw new ArgumentOutOfRangeException("color2Perc");

return Color.FromRgb(
BlendColorChannel(color1.R, color2.R, color2Perc),
BlendColorChannel(color1.G, color2.G, color2Perc),
BlendColorChannel(color1.B, color2.B, color2Perc));
}

private static byte BlendColorChannel(double channel1, double channel2, double channel2Perc)
{
var buff = channel1 + (channel2 - channel1) * channel2Perc / 100D;
return Math.Min((byte)Math.Round(buff), (byte)255);
}

[DllImport("Dwmapi.dll")]
private static extern int DwmIsCompositionEnabled([MarshalAs(UnmanagedType.Bool)] out bool pfEnabled);

[DllImport("Dwmapi.dll", EntryPoint = "#127")] // Undocumented API
private static extern int DwmGetColorizationParameters(out DWMCOLORIZATIONPARAMS parameters);

[StructLayout(LayoutKind.Sequential)]
private struct DWMCOLORIZATIONPARAMS
{
public uint colorizationColor;
public uint colorizationAfterglow;
public uint colorizationColorBalance; // Ranging from 0 to 100
public uint colorizationAfterglowBalance;
public uint colorizationBlurBalance;
public uint colorizationGlassReflectionIntensity;
public uint colorizationOpaqueBlend;
}

Windows 8 theme color - accessing it programmatically

Based on this thread (Start Screen background as my metro apps background) on MSDN - this is not available.

In case the MSDN thread disappears, the site is temporarily unavailable, or Microsoft moves the directory structure around and leaves orphaned links all over the place: The relevant answer there, from Microsoft employee Rob Kaplan, said:

Metro style apps cannot query the start screen background color.

So it can be construed as an official response that this functionality is unavailable.

How to detect when changes are made to the Windows Color and Appearance settings dialog?

The WM_SYSCOLORCHANGE message appears to respond to changes made to the System colors, which also includes changes made from the Window Color and Appearance dialog.

Get Windows 8 current accent colors from desktop app

Arman Stepanyan library is spot on but I decided to create a simple sample project which implements the color retrieving without the need of additional libraries. It was inspired by his library.

You can access it in GitHub here: https://github.com/VladimirAmiorkov/Windows-8-8.1-start-screen-colors-into-desktop-application

Get Modern UI theme colour manually

After reverse engeneeing my system using procmon.exe, I've figured out that the registry key under the path HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Accent\ColorSet_Version3 seems to be the selected color.

I can read and write to it using the registry editor (regedit.exe) and all changes get applied immediately.

EDIT: After some further research, it seems to be read only, changed don't get applied "anymore". There seems to be anything at path HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\SystemProtectedUserData\S-1-5-21-3552576858-2522621019-3615910227-1001\AnyoneRead\Colors\ImmersiveColorIndex_Version3 but I can't manage to change the value (even with admin rights)



Related Topics



Leave a reply



Submit