Home » Category » Microsoft Visual Basic

Microsoft Visual Basic: Colors *Not Resolved*

104| Sun, 02 Dec 2007 10:13:00 GMT| dmitrik| Comments (2)
How do you convert a system color to a pelette color?
For example, in ActiveX, when using following property

Private BGColor as OLE_COLOR
...
Public Property Let BackColor(ByVal newdat As OLE_COLOR)
BGColor = newdat
...

If I select a system color, like vbButtonFace, my BGColor becomes -2something aka black, but if I select a color from Palette menu, the returned value is a valid number for a color. Any ideas? Maybe I'm doing something wrong...it is late after all :)

Keywords & Tags: colors, resolved, microsoft, visual basic, vb

URL: http://www.programmerbase.com/visual-basic/80640/
 
«« Prev - Next »» 2 helpful answers below.
You need to use the GetSysColor API.

Option Explicit

Private Declare Function GetSysColor Lib "user32" (ByVal nIndex As Long) As Long

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_2NDACTIVECAPTION = 27 'Win98 only: 2nd active window color
Const COLOR_2NDINACTIVECAPTION = 28 'Win98 only: 2nd inactive window color

Private Sub Form_Load()
MsgBox GetSysColor(COLOR_BTNFACE)
End Sub

markt | Mon, 03 Dec 2007 20:45:00 GMT |

OK cool thanks, what about OLE_COLOR? What do I use so newdat would accept BOTH palette colors and system colors, which I could convert to a "palette" color later? The problem is when I modify BackColor, the value still returns -2something, and I can't do anything with it. if I take OLE_COLOR and replace it with something else, the color selection box is no longer available.

dmitrik | Mon, 03 Dec 2007 20:46:00 GMT |

Microsoft Visual Basic Hot Answers

Microsoft Visual Basic New questions

Microsoft Visual Basic Related Categories