[SOLVED] Changing the background color registry doesn't update desktop.

Hello!

I want to change the background color!
So i change the registry: HKEY_CURRENT_USER\\Control Panel\\Colors
and in order for the desktop to refresh with the new color, i must restart computer and change one time the desktop background..

How can i avoid the restart thing?

Because the default windows app. changes the registry as well, but somehow updates the color immediatly on the desktop..
Last edited on
Little newbie on windows programming here but i programm 2 years for linux

What syntax should i use for a registry that got edited?

i guess
LONG is SHCNE_ASSOCCHANGED
UINT is SHCNF_IDLIST

and were should i put the path to the registry that got edited? which in this case is HKEY_CURRENT_USER\\Control Panel\\Colors\\Background
Last edited on
You can't force a refresh of the desktop color, use SetSysColors().
http://msdn.microsoft.com/en-us/library/windows/desktop/ms724940
Thanks a lot duky!

So i got it working with this code:

1
2
3
4
int aElements[1] = {COLOR_DESKTOP};
DWORD aNewColors[1];
aNewColors[0] = RGB(0x80, 0x00, 0x80);  // dark purple
SetSysColors(1, aElements, aNewColors);  



But one question, here http://msdn.microsoft.com/en-us/library/ee505488.aspx
it says COLOR_BACKGROUND, COLOR_DESKTOP -> Desktop.

What does COLOR_BACKGROUND changes? because i can't see any difference if i change COLOR_BACKGROUND...

Should as elements i have both COLOR_BACKGROUND, COLOR_DESKTOP or just COLOR_DESKTOP is enough?

It looks like there is no difference, this is from "WinUser.h":

1
2
3
4
...
#if(WINVER >= 0x0400)
#define COLOR_DESKTOP           COLOR_BACKGROUND
...


Aha, ok they are they same :)

Now that i look again, both work perfectly.

Thank you guys ;)
Still something is not working..

So i set the color like this

1
2
3
4
int aElements[1] = {COLOR_BACKGROUND};
DWORD aNewColors[1];
aNewColors[0] = RGB(0x80, 0x00, 0x80);  // dark purple
SetSysColors(1, aElements, aNewColors);


and read the color like this

1
2
3
4
5
6
7
int Elements[1] = {COLOR_BACKGROUND};
DWORD currentColors[1];
currentColors[0] = GetSysColor(Elements[0]);
printf("Current window color: {0x%x, 0x%x, 0x%x}\n", 
        GetRValue(aOldColors[0]), 
        GetGValue(aOldColors[0]), 
        GetBValue(aOldColors[0]));



Reading always outputs the same color
BUT, when i set it via the personalization of windows, the reading part outputs the currect color (the correct one).

In conclusion, something extra must be done when setting the color.


P.S The registry HKEY_CURRENT_USER\\Control Panel\\Colors changes , so this is not the problem
Last edited on
1
2
3
4
5
currentColors[0] = GetSysColor(Elements[0]);
printf("Current window color: {0x%x, 0x%x, 0x%x}\n", 
        GetRValue(aOldColors[0]), 
        GetGValue(aOldColors[0]), 
        GetBValue(aOldColors[0]));
Printing an old array?

SetSysColors() will not update the registry, you'll need to do that yourself if you want the changes to persist after a reboot.
I don't know what i have today

I said on p.s that the registry was changing, while it wasn't

now that i change the registry everything works like a charm.
thanks duky ;)
Last edited on
Topic archived. No new replies allowed.