I am currently trying to write a c# programm that changes the color of the active window in the windows 8 desktop window manager. I focused out the registry entry that contains the specific value and changed it to a value of my choice.
What I'm trying to achieve now is that the color is immediately changed without restarting the window manager (in german "desktopfenster manager" - don't know exactly english name of process).
Here is the code to change the value:
RegistryKey key;
public void initialise()
{
key = Registry.CurrentUser;
key = key.OpenSubKey("Software\\Microsoft\\Windows\\DWM",true);
Object theValue = key.GetValue("ColorizationColor", RegistryValueKind.DWord);
System.Console.Write("Value before switch: ");
System.Console.WriteLine(String.Format("{0:X}", theValue));
System.Console.ReadKey();
}
public void setColor()
{
key.SetValue("ColorizationColor", unchecked((int) 0xff00ff00u), RegistryValueKind.DWord);
Object theValue = key.GetValue("ColorizationColor", RegistryValueKind.DWord);
System.Console.Write("Value after switch: ");
System.Console.WriteLine(String.Format("{0:X}", theValue));
System.Console.ReadKey();
}
Now what I am trying is to send a broadcast message to the window manager to force it to update it's status. Unfortunately, I have never worked with it and cannot figure out what to do exactly.
Google tells me I have to define
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern IntPtr SendMessageTimeout(
IntPtr hWnd,
int Msg,
IntPtr wParam,
string lParam,
int fuFlags,
int uTimeout,
IntPtr lpdwResult
);
And then call it in my function like this:
SendMessageTimeout((IntPtr)0xffff, 0x001A, IntPtr.Zero, "Environment",
2, 5000, IntPtr.Zero);
This does not work, plus I don't know if I am on the right way here anyway. However, the color changes after relogging into my user account.
Ah, I should add that in the end the programm should randomly change the color of the window by changing the value of
HKEY_CURRENT_USER\Software\Microsoft\Windows\DWM\ColorizationColor
to get a kind of "Rainbow Window".
I have also given
HKEY_CURRENT_USER\Software\Microsoft\Windows\DWM\ColorizationColorBalance
an alpha value of 00 (while ColorizationColor has ff at the beginning)