Summary:
Retrieve the starting or ending gradient colors currently in use for window titlebars - active or inactive.
Please note: This code requires Win 98/ME/2k/XP. You would probably want to check for Windows version before executing this code. Also, it is possible for the user to have disabled the titlebar gradient effect - something else to test for.
VB Code:
'declare api functions
Private Declare Function GetSysColor Lib "user32" _
(ByVal nIndex As Long) As Long
'declare constants
Private Const COLOR_ACTIVECAPTION = 2
Private Const COLOR_INACTIVECAPTION = 3
Private Const COLOR_GRADIENTACTIVECAPTION = 27
Private Const COLOR_GRADIENTINACTIVECAPTION = 28
'declare types
Private Type RGB
r As Integer
G As Integer
B As Integer
End Type
Private Function GetRGBColors(ColorValue As Long) As RGB
On Error Resume Next
'initialize
Dim strColorHex As String
'convert color value into string representing hex value
strColorHex = String(6 - Len(Hex(ColorValue)), "0") & Hex(ColorValue)
'return rgb values
GetRGBColors.r = "&H" & Mid(strColorHex, 5, 2) & "00"
GetRGBColors.G = "&H" & Mid(strColorHex, 3, 2) & "00"
GetRGBColors.B = "&H" & Mid(strColorHex, 1, 2) & "00"
End Function
Usage Example:
VB Code:
Dim rgbColorStart as RGB
Dim rgbColorEnd as RGB
'for active gradient colors:
rgbColorStart = GetRGBColors(GetSysColor(COLOR_ACTIVECAPTION))
rgbColorEnd = GetRGBColors(GetSysColor(COLOR_GRADIENTACTIVECAPTION))
'for inactive gradient colors:
rgbColorStart = GetRGBColors(GetSysColor(COLOR_INACTIVECAPTION))
rgbColorEnd = GetRGBColors(GetSysColor(COLOR_GRADIENTINACTIVECAPTION))
Notes:
The declarations for API functions, constants, types and the GetRGBColors function can be moved to a module. If so, they should be declared as Public.
See Also:
Determine if TitleBar Gradient is Enabled
Determine Windows Version