Article ID: 82158 - View products that this article applies to.
This article was previously published under Q82158
This article describes how to use the GetSysColor and SetSysColors API functions to set the system colors for various parts of the display in Microsoft Windows. This allows you to change the Windows display programmatically, instead of using the Windows Control Panel.
Windows maintains an internal array of 19 color values that it uses to paint the different parts of the Windows display. Changing any of these values will affect all windows for all applications running under Windows. Note that the SetSysColors routine only changes the internal system list. This means that any changes made using SetSysColors will only be valid for the current Windows session. To make these changes permanent, you need to change the [COLORS] section of the Windows initialization file, WIN.INI.
For more information on modifying the Windows initialization file programmatically, query on the following words in the Microsoft Knowledge Base:
GetProfileString and WriteProfileString
To use the GetSysColor and SetSysColors functions within a Visual Basic for Window application, you must first declare them in the Declarations section of your Code window.
Declare the Function statement as follows:
NOTE: Each Declare statement above must be written on one line.
The parameters are defined as follows:
Parameter Definition ------------------------------------------------------------- nIndex% Specifies the display element whose color is to be retrieved. See the list below to find the index value for the corresponding display element. nChanges% Specifies the number of system colors to be changed. lpSysColor% Identifies the array of integer indexes that specify the elements to be changed. lpColorValues& Identifies the array of long integers that contain the new RGB color values for each element to be changed.
The following system color indexes are defined using the predefined constants found in the WINDOWS.H file supplied with the Microsoft Windows Software Development Kit (SDK). The corresponding value is the value placed in the lpSysColor% array.
List of System Color Indexes
Windows.H Definition Value Description ------------------------------------------------------- COLOR_SCROLLBAR 0 Scroll-bar gray area COLOR_BACKGROUND 1 Desktop COLOR_ACTIVECAPTION 2 Active window caption COLOR_INACTIVECAPTION 3 Inactive window caption COLOR_MENU 4 Menu background COLOR_WINDOW 5 Window background COLOR_WINDOWFRAME 6 Window frame COLOR_MENUTEXT 7 Text in menus COLOR_WINDOWTEXT 8 Text in windows COLOR_CAPTIONTEXT 9 Text in caption, size box, scroll bar arrow box COLOR_ACTIVEBORDER 10 Active window border COLOR_INACTIVEBORDER 11 Inactive window border COLOR_APPWORKSPACE 12 Background color of multiple document interface (MDI) applications COLOR_HIGHLIGHT 13 Items selected item in a control COLOR_HIGHLIGHTTEXT 14 Text of item selected in a control COLOR_BTNFACE 15 Face shading on push button COLOR_BTNSHADOW 16 Edge shading on push button COLOR_GRAYTEXT 17 Grayed (disabled) text. This color is set to 0 if the current display driver does not support a solid gray color. COLOR_BTNTEXT 18 Text on push buttons
The following is an example of how to set the system colors for different parts of the Windows display:
Article ID: 82158 - Last Review: November 18, 2003 - Revision: 2.0
Retired KB Content Disclaimer
This article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.
Contact us for more help