Results 1 to 12 of 12

Thread: System Colors

  1. #1

    Thread Starter
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808

    System Colors

    Is there anyway to "translate" the system's colors into their RGB components? Or at least into the positive long number it is represented with?
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  2. #2

    Thread Starter
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    Never mind... I've solved it already.
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  3. #3

    Thread Starter
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  4. #4
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654
    In case you are or someone else is interested:

    VB Code:
    1. 'in a module
    2. Public Declare Function GetSysColor Lib "user32" (ByVal nIndex As Long) As Long

    It returns a direct long color value. Usage:

    VB Code:
    1. BackColor = GetSysColor(0)
    2.     ForeColor = GetSysColor(28) 'this is the last index that gives a result


  5. #5

    Thread Starter
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    I already knew that function, but was of no use. The parameter it needs is a constant (which usually starts with "COLOR_". This constants are positive numbers... what if the long you have is -2147483646 ? The GetSysColor API returns always 0.
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  6. #6

    Thread Starter
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    Originally posted by Merri
    VB Code:
    1. BackColor = GetSysColor(0)
    2.     ForeColor = GetSysColor(28) 'this is the last index that gives a result

    VB Code:
    1. Const COLOR_SCROLLBAR = 0 'The Scrollbar colour
    2. Const COLOR_BACKGROUND = 1 'Colour of the background with no wallpaper
    3. Const COLOR_ACTIVECAPTION = 2 'Caption of Active Window
    4. Const COLOR_INACTIVECAPTION = 3 'Caption of Inactive window
    5. Const COLOR_MENU = 4 'Menu
    6. Const COLOR_WINDOW = 5 'Windows background
    7. Const COLOR_WINDOWFRAME = 6 'Window frame
    8. Const COLOR_MENUTEXT = 7 'Window Text
    9. Const COLOR_WINDOWTEXT = 8 '3D dark shadow (Win95)
    10. Const COLOR_CAPTIONTEXT = 9 'Text in window caption
    11. Const COLOR_ACTIVEBORDER = 10 'Border of active window
    12. Const COLOR_INACTIVEBORDER = 11 'Border of inactive window
    13. Const COLOR_APPWORKSPACE = 12 'Background of MDI desktop
    14. Const COLOR_HIGHLIGHT = 13 'Selected item background
    15. Const COLOR_HIGHLIGHTTEXT = 14 'Selected menu item
    16. Const COLOR_BTNFACE = 15 'Button
    17. Const COLOR_BTNSHADOW = 16 '3D shading of button
    18. Const COLOR_GRAYTEXT = 17 'Grey text, of zero if dithering is used.
    19. Const COLOR_BTNTEXT = 18 'Button text
    20. Const COLOR_INACTIVECAPTIONTEXT = 19 'Text of inactive window
    21. Const COLOR_BTNHIGHLIGHT = 20 '3D highlight of button
    22. Const COLOR_INFOBK = 24 'Tooltip
    23. Const COLOR_2NDACTIVECAPTION = 27 'Win98 only: 2nd active window color
    24. Const COLOR_2NDINACTIVECAPTION = 28 'Win98 only: 2nd inactive window color
    If anyone knows any other... please post it here.
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  7. #7
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654
    You mean this?

    VB Code:
    1. Public Function ProperColor(ByVal Color As Long) As Long
    2.     If Color And &H80000000 Then
    3.         'it is a system color
    4.         ProperColor = GetSysColor(Color And &HFF)
    5.     Else
    6.         'make sure it is a proper color
    7.         ProperColor = Color And &HFFFFFF
    8.     End If
    9. End Sub

    Didn't test but should work.


    Also, you might find this document interesting: http://www.tomorrowssolutionsllc.com...4everyone.html

  8. #8

    Thread Starter
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    This code seems to work:
    VB Code:
    1. Option Explicit
    2. Private Declare Function OleTranslateColor Lib "OLEPRO32.DLL" (ByVal OLE_COLOR _
    3.     As Long, ByVal HPALETTE As Long, pccolorref As Long) As Long
    4. Private Declare Function GetSysColor Lib "user32" (ByVal nIndex As Long) As Long
    5.  
    6. ' convert a VB color constant to a COLORREF
    7. ' accepts both RGB() values and system color constants
    8.  
    9. Function TranslateColor(ByVal clr As Long) As Long
    10.     If OleTranslateColor(clr, 0, TranslateColor) Then
    11.          TranslateColor = -1
    12.     End If
    13. End Function
    14.  
    15. Private Sub Form_Load()
    16.     Debug.Print TranslateColor(-2147483646)
    17.     Debug.Print ProperColor(-2147483646)
    18. End Sub
    19.  
    20. Public Function ProperColor(ByVal Color As Long) As Long
    21.     If Color And &H80000000 Then
    22.         'it is a system color
    23.         ProperColor = GetSysColor(Color And &HFF)
    24.     Else
    25.         'make sure it is a proper color
    26.         ProperColor = Color And &HFFFFFF
    27.     End If
    28. End Function
    Don't know if it works "always".
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  9. #9
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654
    Well, my code works in each case, I just tested it. The code you posted gives an error when a given input is invalid, because a color can't be &HFFFFFFFF (= -1).

    Anyways, I made a speed test as well, the speed of both ways is rather equal.

  10. #10

    Thread Starter
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    Originally posted by Merri
    The code you posted gives an error when a given input is invalid, because a color can't be &HFFFFFFFF (= -1).
    Do you mean the line TranslateColor = -1. Because that would be an error condition. You call the function and if you get -1... the input was invalid => stop processing it.
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  11. #11
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654
    Well, I thought the whole point of the function would be to get a proper color, ie. the usage would be:

    VB Code:
    1. BackColor = ProperColor(AnyColorThatGoesIn)

    This would save time checking for a color. If you wanted to check beforehand if you can use the color, a better function for that would be:

    VB Code:
    1. Public Function IsProperColor(ByVal Color As Long) As Boolean
    2.     If Color And &H80000000 Then
    3.         If (Color And &HFF) < 31 Then IsProperColor = True
    4.     Else
    5.         If Color < &H1000000 Then IsProperColor = True
    6.     End If
    7. End Function

    Just because it would be much faster than calling an API

  12. #12

    Thread Starter
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    I'll bear it in mind. Thanks!!
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width