|
-
Aug 9th, 2004, 08:47 AM
#1
Thread Starter
Need-a-life Member
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.
-
Aug 9th, 2004, 09:01 AM
#2
Thread Starter
Need-a-life Member
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.
-
Aug 9th, 2004, 09:45 AM
#3
Thread Starter
Need-a-life Member
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.
-
Aug 9th, 2004, 09:58 AM
#4
In case you are or someone else is interested:
VB Code:
'in a module
Public Declare Function GetSysColor Lib "user32" (ByVal nIndex As Long) As Long
It returns a direct long color value. Usage:
VB Code:
BackColor = GetSysColor(0)
ForeColor = GetSysColor(28) 'this is the last index that gives a result
-
Aug 9th, 2004, 10:02 AM
#5
Thread Starter
Need-a-life Member
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.
-
Aug 9th, 2004, 10:05 AM
#6
Thread Starter
Need-a-life Member
Originally posted by Merri
VB Code:
BackColor = GetSysColor(0)
ForeColor = GetSysColor(28) 'this is the last index that gives a result
VB Code:
Const COLOR_SCROLLBAR = 0 'The Scrollbar colour
Const COLOR_BACKGROUND = 1 'Colour of the background with no wallpaper
Const COLOR_ACTIVECAPTION = 2 'Caption of Active Window
Const COLOR_INACTIVECAPTION = 3 'Caption of Inactive window
Const COLOR_MENU = 4 'Menu
Const COLOR_WINDOW = 5 'Windows background
Const COLOR_WINDOWFRAME = 6 'Window frame
Const COLOR_MENUTEXT = 7 'Window Text
Const COLOR_WINDOWTEXT = 8 '3D dark shadow (Win95)
Const COLOR_CAPTIONTEXT = 9 'Text in window caption
Const COLOR_ACTIVEBORDER = 10 'Border of active window
Const COLOR_INACTIVEBORDER = 11 'Border of inactive window
Const COLOR_APPWORKSPACE = 12 'Background of MDI desktop
Const COLOR_HIGHLIGHT = 13 'Selected item background
Const COLOR_HIGHLIGHTTEXT = 14 'Selected menu item
Const COLOR_BTNFACE = 15 'Button
Const COLOR_BTNSHADOW = 16 '3D shading of button
Const COLOR_GRAYTEXT = 17 'Grey text, of zero if dithering is used.
Const COLOR_BTNTEXT = 18 'Button text
Const COLOR_INACTIVECAPTIONTEXT = 19 'Text of inactive window
Const COLOR_BTNHIGHLIGHT = 20 '3D highlight of button
Const COLOR_INFOBK = 24 'Tooltip
Const COLOR_2NDACTIVECAPTION = 27 'Win98 only: 2nd active window color
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.
-
Aug 9th, 2004, 10:13 AM
#7
You mean this?
VB Code:
Public Function ProperColor(ByVal Color As Long) As Long
If Color And &H80000000 Then
'it is a system color
ProperColor = GetSysColor(Color And &HFF)
Else
'make sure it is a proper color
ProperColor = Color And &HFFFFFF
End If
End Sub
Didn't test but should work.
Also, you might find this document interesting: http://www.tomorrowssolutionsllc.com...4everyone.html
-
Aug 9th, 2004, 10:19 AM
#8
Thread Starter
Need-a-life Member
This code seems to work:
VB Code:
Option Explicit
Private Declare Function OleTranslateColor Lib "OLEPRO32.DLL" (ByVal OLE_COLOR _
As Long, ByVal HPALETTE As Long, pccolorref As Long) As Long
Private Declare Function GetSysColor Lib "user32" (ByVal nIndex As Long) As Long
' convert a VB color constant to a COLORREF
' accepts both RGB() values and system color constants
Function TranslateColor(ByVal clr As Long) As Long
If OleTranslateColor(clr, 0, TranslateColor) Then
TranslateColor = -1
End If
End Function
Private Sub Form_Load()
Debug.Print TranslateColor(-2147483646)
Debug.Print ProperColor(-2147483646)
End Sub
Public Function ProperColor(ByVal Color As Long) As Long
If Color And &H80000000 Then
'it is a system color
ProperColor = GetSysColor(Color And &HFF)
Else
'make sure it is a proper color
ProperColor = Color And &HFFFFFF
End If
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.
-
Aug 9th, 2004, 10:31 AM
#9
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.
-
Aug 9th, 2004, 10:39 AM
#10
Thread Starter
Need-a-life Member
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.
-
Aug 9th, 2004, 10:45 AM
#11
Well, I thought the whole point of the function would be to get a proper color, ie. the usage would be:
VB Code:
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:
Public Function IsProperColor(ByVal Color As Long) As Boolean
If Color And &H80000000 Then
If (Color And &HFF) < 31 Then IsProperColor = True
Else
If Color < &H1000000 Then IsProperColor = True
End If
End Function
Just because it would be much faster than calling an API
-
Aug 9th, 2004, 10:48 AM
#12
Thread Starter
Need-a-life Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|