PDA

View Full Version : Solved: Can't Get Screen Colors Right



Cyberdude
04-28-2005, 02:03 PM
I have always been annoyed by my inability to set my screen ?Appearance? in a fashion that allows me to read whatever text is shown on my screen. Yes, I do know how to change the parameters by going into the screen Properties, click Appearance then Advanced to get to the list of items that I can customize the color of. I have worked with it till I?m blue (so to speak) in the face. It?s like trying to put a cat in a bucket of water . . . there?s always one leg sticking out.

Although one of my problems is that I much prefer to have my desktop and Excel worksheet background black (it shows off colors much more vividly), I have tried to use the standard XP color scheme, and I still run into problems now and then.

For example, on the MrExcel forum, any area that I have to enter information into (userid, password, posted text) always appears with a black background, but the text feedback I get must also be black because I can?t see it. I can run my cursor over it, and it will temporarily change color and show the text. I get the same exact problem when I use the Kaiser Permanente site (my HMO). A lot of (but not all) the VBA Help screens I view tend to have a black background, then some of the text is displayed in dark blue (VERY hard to read). Other VBA Help screens are fine ? they have a white background with black text. Good stuff!

I run into some screens that use a light blue or white background, then show their text in cyan. Whew, that?s a strain to see. When I view Help and Support I see a window with white background, and text that is cyan or (gasp!) white. While I can choose Appearance parameters that correct these specific problems, then something else becomes difficult to read. (It?s the fourth leg of the cat.) For MrExcel I can (and do) change the appearance of the Windows item to have cyan as the background with a black font for text. That works great. But then my desktop and Excel worksheets are all cyan. Not so great.

I can?t believe that I?m the only one who has this problem. My question is, is there a way to run a VBA macro or maybe VB script to make a quick change for those cases when I need it, and then change back when I?m finished? :motz2:

Killian
05-04-2005, 06:00 PM
Hi there,

there's a couple of ways to do this...
Your appearance settings are held in the registry at this location
HKEY_CURRENT_USER\Control Panel\Colors

Now, you're going to backup your registry before you do this, right?

Good. :thumb

You can access the registry quite easily using the Windows Scripting Host from a VBScript.
Here's a sample snippet from one of my install scripts for setting a PowerPoint AddIn to Auto LoadSet WSHShell = CreateObject("WScript.Shell")

RegKey = "HKEY_LOCAL_MACHINE\Software\Microsoft\Office\11.0\PowerPoint\AddIns\"
NewKey= "Custom_PPT_AddIn"
PathValue = "C:\Program Files\OfficeCode\Custom_PPT_AddIn.ppa"

WSHShell.RegWrite regkey, NewKey
WSHShell.RegWrite regkey & NewKey & "\AutoLoad", 1, "REG_DWORD"
WSHShell.RegWrite regkey & NewKey & "\Path", PathValue, "REG_SZ"You could build up a bunch of scripts for each of your color schemes.

There is, of course, more than one way to skin a cat (presumably dunking it in the bucket of water was just to soften it up... I'm not sure I'm comfortable with these analogies, :eek: even if I am more of a dog person)

The Windows API can set the appearance colors directly so can be used from VBA. Here's a taster'#####################################################
'adapted from code example at: http://www.allapi.net/
'#####################################################

'declare required API functions
Private Declare Function SetSysColors Lib "user32" (ByVal nChanges As Long, lpSysColor As Long, lpColorValues As Long) As Long
Private Declare Function GetSysColor Lib "user32" (ByVal nIndex As Long) As Long

'values and descriptions of the syscolor constants
Const COLOR_SCROLLBAR = 0 'The Scrollbar colour
Const COLOR_BACKGROUND = 1 'Colour of the background with no wallpaper
Const COLOR_ACTIVECAPTION = 2 'Caption of Active Window
Const COLOR_INACTIVECAPTION = 3 'Caption of Inactive window
Const COLOR_MENU = 4 'Menu
Const COLOR_WINDOW = 5 'Windows background
Const COLOR_WINDOWFRAME = 6 'Window frame
Const COLOR_MENUTEXT = 7 'Window Text
Const COLOR_WINDOWTEXT = 8 '3D dark shadow (Win95)
Const COLOR_CAPTIONTEXT = 9 'Text in window caption
Const COLOR_ACTIVEBORDER = 10 'Border of active window
Const COLOR_INACTIVEBORDER = 11 'Border of inactive window
Const COLOR_APPWORKSPACE = 12 'Background of MDI desktop
Const COLOR_HIGHLIGHT = 13 'Selected item background
Const COLOR_HIGHLIGHTTEXT = 14 'Selected menu item
Const COLOR_BTNFACE = 15 'Button
Const COLOR_BTNSHADOW = 16 '3D shading of button
Const COLOR_GRAYTEXT = 17 'Grey text, of zero if dithering is used.
Const COLOR_BTNTEXT = 18 'Button text
Const COLOR_INACTIVECAPTIONTEXT = 19 'Text of inactive window
Const COLOR_BTNHIGHLIGHT = 20 '3D highlight of button
Const COLOR_2NDACTIVECAPTION = 27 'Win98 only: 2nd active window color
Const COLOR_2NDINACTIVECAPTION = 28 'Win98 only: 2nd inactive window color

Private Sub TestColorChange()
'this example changes the desktop color
'and reports the change with the old and new value
Dim OldColor, NewColor

'Get the caption's active color
OldColor = GetSysColor(COLOR_BACKGROUND)
'Change the active caption's color to red
NewColor = SetSysColors(1, COLOR_BACKGROUND, RGB(255, 0, 0))
MsgBox "The original desktop color: " & CStr(OldColor) & Chr(13) & _
"Current desktop color: " & CStr(GetSysColor(COLOR_BACKGROUND))

End SubThat should keep you busy for a while... :devil:

Cyberdude
05-04-2005, 08:40 PM
Migawd, Killian! I asked for the time, and you told me how to make a watch. That is REALLY super stuff. I genuinely appreciate your taking the time to educate me. You're filling in some more holes in the teeth of my experience. I WILL take the time to study it and run some tests. I want very much for this to work. Thanx again. :bow:

Cyberdude
05-13-2005, 08:29 AM
Killian, I forgot to mention it, but thanks to you I was able to write a macro to quickly switch my screen appearance as needed. I just click a button on my toolbar now. That takes care of a long-standing annoyance. :bow:

Killian
05-13-2005, 09:47 AM
Kewl.
It's reassuring to know no corner of Windows is safe from a determined VBA programmer :devil: