Gary Hengeveld
Gary Hengeveld

Reputation: 55

Windows reads color value from registry wrong

I am writing a vb.net program that allows me to set custom default start ui colors. I write the colors to the registry this way.

My.Computer.Registry.SetValue( _
    "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Accent", _
    "DefaultStartColor", _
    MainForm.btnStartColor.BackColor.GetHashCode.ToString, _
    RegistryValueKind.DWord)

The code works fine and changes the color. The problem is that the color that windows changes to is different than the code entered in the registry.

Example:

If I choose a yellow color numbered: ffffff80 from color dialog control.

It will change the color of btnStartColor.backcolor in the program to yellow and saves the code to the registry as ffffff80(4294967168) but when I log into windows the next time the color windows 8 translates this to is a baby blue.

Am I translating it incorrectly or using the wrong color settings?

The funniest thing is that the default color ff3c3c3c(4282137660) works fine and shows up as the correct grey color.

Here is a test code I made to describe this issue better:

Dim BC As String = MainForm.btnStartColor.BackColor.ToArgb
My.Computer.Registry.SetValue( _
    "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Accent", _
    "StartColor", BC, RegistryValueKind.DWord)

MainForm.BackColor = ColorTranslator.FromHtml( _
    My.Computer.Registry.GetValue( _
    "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Accent", _
    "StartColor", Nothing))

this code will make the background of my program's main form the correct color but windows start ui is shows another color. ex. if I enter orange the registry DWORD is 0xffff8000(4294934528) Windows Start ui shows a blue color

Upvotes: 0

Views: 957

Answers (1)

Rotem
Rotem

Reputation: 21917

Why do you believe GetHashCode returns the correct byte order that windows is looking for?

If 0xFFFFFF80 result in a blue, then the correct byte order is most likely ABGR.

You can create the correct value like this:

uint V = (((((0xFFu << 8) | c.B) << 8) | c.G) << 8) | c.R;

Upvotes: 2

Related Questions