How to Set Windows System Colors Using API and Visual BasicLast reviewed: June 21, 1995Article ID: Q82158 |
|
The information in this article applies to:
- Standard and Professional Editions of Microsoft Visual Basic for Windows, versions 2.0 and 3.0- Microsoft Visual Basic programming system for Windows, version 1.0
SUMMARYThis 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.
MORE INFORMATIONWindows 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 WriteProfileStringTo 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:
Declare Function GetSysColor Lib "User" (ByVal nIndex%) As Long
Declare Sub SetSysColors Lib "User" (ByVal nChanges%,
lpSysColor%,
lpColorValues&)
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 IndexesWindows.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:
|
Additional reference words: 1.00 2.00 3.00
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |