Click to See Complete Forum and Search --> : Refreshing windows colours


September 16th, 1999, 08:54 PM
I have written a program which modifies the colour scheme for windows via the registry. What I'm trying to figure out is what are the series of API calls I must make to force windows to refresh itself as it does when you click the apply button in the display control panel. I have tried the SendMessage API with no luck so far.

marshall@pssnet.com

Lothar Haensler
September 17th, 1999, 01:26 AM
instead of writing to the registry you should call the SetSyscolors API.

September 17th, 1999, 01:16 PM
Great! Thanks for the responce. I'll try that later on tonight!

I'd still like to know how to force a refresh though - if anyone knows.

September 17th, 1999, 08:28 PM
Okay, I just tried this, and it seems to be doing something, but its not changing the colours in windows.
Here is what I have...

In the form I have this:

private Sub Form_Click()
picColour.BackColor = GetColour(COLOR_SCROLLBAR)
SetColour COLOR_SCROLLBAR, RGB(255, 0, 0)
End Sub



What this does is it reads in the colour returned by the GetSysColor API call and displays it in picColour.
Then I procede to try to set this colour to red.


public Function GetColour(i as Integer) as Long
GetColour = GetSysColor(i)
End Function




Okay, this code gets the system colour fine. It appears to return the proper colours for the items I try.


public Function SetColour(byval i as Integer, Colour as Long)
Dim C(0 to 0) as Long
Dim N(0 to 0) as Long
N(0) = i
C(0) = Colour
SetSysColors 1, N(0), C(0)
End Function




This is where I think the problem is. SetSysColors says it uses the first statement as a counter. The other 2 are arrays which contain all of the needed information. I've tried a number of things on this line, but the scroll bars do not want to change colours. The one weird result is, one of my variations actually wrote something, and now the picture box comes up red.


SetSysColors 1, i, VarPtr(C(0))



Seems to write the colour somewhere. The only problem is, it doesn't show this change in windows, and it doesn't show up in the registry under CURRENT_USER/Control Panel/Colors. When I run the program a 2nd/3rd time, this change still appears to be there, which suggests that its writing this information somewhere in memory, but not the correct spot. This leads me to believe that an array of long in VB is not the same as an array of long in C and when I pass it the pointer, the information is setup differently. (All of the windows do refresh, which makes it look like its trying to change the colours)

What else I've found (or not found) is that if I change the registry directly, then run the setsyscolor api, the colour change isn't taken into effect. This looks like its only read when you boot up, at all other times, the colours are stored in memory.

- For those of you who didn't know, VarPtr is an undocumented VB command - Probably because of people like me :D

Any help would be great!

Ximmer
September 18th, 1999, 02:32 PM
I think the reason Varptr is undocumented is because It's usually not a good idea to modify the contents of memory in windows applicatins that may dynamicaly modify the memory's location. And I am Curious...

Are Peek, Poke, Def Seg, and VarSeg undocumented as well???

September 19th, 1999, 03:39 PM
None of those seem to work. Only VarPtr does.