Declare Function SetSysColors Lib "user32.dll" (ByVal cElements As Long, lpaElements As Long, lpaRgbValues As Long) As Long
SetSysColors changes the system colors used by Windows. Windows uses these colors when displaying the typical widgets such as title bars, scroll bars, the desktop, menus, etc. This function can set multiple different system colors simultaneously, by passing all the new RGB color values in an array. SetSysColors also notifies all windows of the change, so the color change takes effect immediately. However, the new colors are not saved after Windows shuts down.
If successful, the function returns a nonzero value. If an error occured, the function returns zero (use GetLastError to get the error code).
None.
Const COLOR_3DDKSHADOW = 21
Const COLOR_3DFACE = COLOR_BTNFACE
Const COLOR_3DHIGHLIGHT = COLOR_BTNHIGHLIGHT
Const COLOR_3DHILIGHT = COLOR_BTNHIGHLIGHT
Const COLOR_3DLIGHT = 22
Const COLOR_3DSHADOW = COLOR_BTNSHADOW
Const COLOR_ACTIVEBORDER = 10
Const COLOR_ACTIVECAPTION = 2
Const COLOR_APPWORKSPACE = 12
Const COLOR_BACKGROUND = 1
Const COLOR_BTNFACE = 15
Const COLOR_BTNHIGHLIGHT = 20
Const COLOR_BTNHILIGHT = COLOR_BTNHIGHLIGHT
Const COLOR_BTNSHADOW = 16
Const COLOR_BTNTEXT = 18
Const COLOR_CAPTIONTEXT = 9
Const COLOR_DESKTOP = COLOR_BACKGROUND
Const COLOR_GRADIENTACTIVECAPTION = 27
Const COLOR_GRADIENTINACTIVECAPTION = 28
Const COLOR_GRAYTEXT = 17
Const COLOR_HIGHLIGHT = 13
Const COLOR_HIGHLIGHTTEXT = 14
Const COLOR_HOTLIGHT = 26
Const COLOR_INACTIVEBORDER = 11
Const COLOR_INACTIVECAPTION = 3
Const COLOR_INACTIVECAPTIONTEXT = 19
Const COLOR_INFOBK = 24
Const COLOR_INFOTEXT = 23
Const COLOR_MENU = 4
Const COLOR_MENUTEXT = 7
Const COLOR_SCROLLBAR = 0
Const COLOR_WINDOW = 5
Const COLOR_WINDOWFRAME = 6
Const COLOR_WINDOWTEXT = 8
Reverse the gradient colors in windows' title bars. In other words, the left-side gradient color is swapped with the right-side gradient color, for both active and inactive windows. After making the change, a notification is sent to all windows, to insure that the change takes effect immediately. Of course, this example won't work properly on Windows 95 or Windows NT 3.1 through 4.0, but you can still see how these two functions are used by looking at the source code.
This example runs when the user clicks command button Command1. So, to use this example, you must first place a command button named Command1 on a form window.
' This code is licensed according to the terms and conditions listed here.
' Declarations and such needed for the example:
' (Copy them to the (declarations) section of a module.)
Public Declare Function GetSysColor Lib "user32.dll" (ByVal nIndex As Long) As Long
Public Declare Function SetSysColors Lib "user32.dll" (ByVal cElements As Long, lpaElements As Long, _
lpaRgbValues As Long) As Long
Public Const COLOR_ACTIVECAPTION = 2
Public Const COLOR_GRADIENTACTIVECAPTION = 27
Public Const COLOR_GRADIENTINACTIVECAPTION = 28
Public Const COLOR_INACTIVECAPTION = 3
' *** Place the following code inside a form window. ***
Private Sub Command1_Click()
Dim activeLeftColor As Long ' color of left-side gradient of active window title bar
Dim activeRightColor As Long ' color of right-side gradient of active window title bar
Dim inactiveLeftColor As Long ' color of the left-side gradient of inactive window title bar
Dim inactiveRightColor As Long ' color of the right-side gradient of inactive window title bar
Dim colorNames(0 To 3) As Long ' identifiers of the system colors to change
Dim colorRGBs(0 To 3) As Long ' RGB values of the system colors to change
Dim retval As Long ' generic return value
' Get the RGB values of the colors used in title bars.
activeLeftColor = GetSysColor(COLOR_ACTIVECAPTION)
activeRightColor = GetSysColor(COLOR_GRADIENTACTIVECAPTION)
inactiveLeftColor = GetSysColor(COLOR_INACTIVECAPTION)
inactiveRightColor = GetSysColor(COLOR_GRADIENTINACTIVECAPTION)
' Load the arrays with the new values to assign. Note how we're switching
' the values used on the left and right sides of the two gradients.
colorNames(0) = COLOR_ACTIVECAPTION
colorRGBs(0) = activeRightColor
colorNames(1) = COLOR_GRADIENTACTIVECAPTION
colorRGBs(1) = activeLeftColor
colorNames(2) = COLOR_INACTIVECAPTION
colorRGBs(2) = inactiveRightColor
colorNames(3) = COLOR_GRADIENTINACTIVECAPTION
colorRGBs(3) = inactiveLeftColor
' Change the system color settings as specified above.
retval = SetSysColors(4, colorNames(0), colorRGBs(0))
End Sub
Back to the Function list.
Back to the Reference section.
Last Modified: September 24, 2000
This page is copyright © 2000 Paul Kuliniewicz.
Copyright Information Revised October 29, 2000
Go back to the Windows API Guide home page.
E-mail: vbapi@vbapi.com Send Encrypted E-Mail
This page is at http://www.vbapi.com/ref/s/setsyscolors.html