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:
  1. 'declare api functions
  2.     Private Declare Function GetSysColor Lib "user32" _
  3.         (ByVal nIndex As Long) As Long
  4.  
  5. 'declare constants
  6.     Private Const COLOR_ACTIVECAPTION = 2
  7.     Private Const COLOR_INACTIVECAPTION = 3
  8.     Private Const COLOR_GRADIENTACTIVECAPTION = 27
  9.     Private Const COLOR_GRADIENTINACTIVECAPTION = 28
  10.  
  11. 'declare types
  12.     Private Type RGB
  13.         r As Integer
  14.         G As Integer
  15.         B As Integer
  16.     End Type
  17.  
  18. Private Function GetRGBColors(ColorValue As Long) As RGB
  19.     On Error Resume Next
  20.    
  21.     'initialize
  22.     Dim strColorHex As String
  23.  
  24.     'convert color value into string representing hex value
  25.     strColorHex = String(6 - Len(Hex(ColorValue)), "0") & Hex(ColorValue)
  26.  
  27.     'return rgb values
  28.     GetRGBColors.r = "&H" & Mid(strColorHex, 5, 2) & "00"
  29.     GetRGBColors.G = "&H" & Mid(strColorHex, 3, 2) & "00"
  30.     GetRGBColors.B = "&H" & Mid(strColorHex, 1, 2) & "00"
  31. End Function

Usage Example:
VB Code:
  1. Dim rgbColorStart as RGB
  2. Dim rgbColorEnd as RGB
  3.  
  4. 'for active gradient colors:
  5. rgbColorStart = GetRGBColors(GetSysColor(COLOR_ACTIVECAPTION))
  6. rgbColorEnd = GetRGBColors(GetSysColor(COLOR_GRADIENTACTIVECAPTION))
  7.  
  8. 'for inactive gradient colors:
  9. rgbColorStart = GetRGBColors(GetSysColor(COLOR_INACTIVECAPTION))
  10. 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