Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

getting system colors 2

Status
Not open for further replies.

daimaou

Programmer
Apr 4, 2001
154
PT
I'm trying to get some colors from the settings of my windows.
Like the colors I have set for the selected items, menus, etc (The ones you set on the properties window).
I need to get the colors I have set on my system for this, I don't know if this is easy to access or not, but if anyone knows how to do this could plz let me know.

Thanks
 
You can use the GetSysColor and SetSysColors API routines in user32.dll. They should be able to what you need.
Drider



GetSysColor

VB Declaration


Code:
Declare Function GetSysColor& Lib "user32" (ByVal nIndex As Long)

Description


Determines the color of the specified Windows display object.

Parameter Type/Description
nIndex Long—Constant specifying a Windows display object as shown in the table that follows.
Constant Definition Windows Object
COLOR_ACTIVEBORDER Border of active window
COLOR_ACTIVECAPTION Caption of active window
COLOR_APPWORKSPACE Background of MDI desktop
COLOR_BACKGROUND Windows desktop
COLOR_BTNFACE Button
COLOR_BTNHIGHLIGHT 3D highlight of button
COLOR_BTNSHADOW 3D shading of button
COLOR_BTNTEXT Button text
COLOR_CAPTIONTEXT Text in window caption
COLOR_GRAYTEXT Gray text, or zero if dithering is used
COLOR_HIGHLIGHT Selected item background
COLOR_HIGHLIGHTTEXT Selected item text
COLOR_INACTIVEBORDER Border of inactive window
COLOR_INACTIVECAPTION Caption of inactive window
COLOR_INACTIVECAPTIONTEXT Text of inactive window
COLOR_MENU Menu
COLOR_MENUTEXT Menu text
COLOR_SCROLLBAR Scroll Bar
COLOR_WINDOW Window background
COLOR_WINDOWFRAME Window frame
COLOR_WINDOWTEXT Window text
COLOR_3DDKSHADOW 3D dark shadow*
COLOR_3DFACE Face color for 3D shaded objects*
COLOR_3DHILIGHT 3D Highlight color (Win95)
COLOR_3DLIGHT Light color for 3D shaded objects*
COLOR_INFOBK Tooltip background color*
COLOR_INFOTEXT Tooltip text color*
Constants with an asterisk are not be supported under NT 3.51

Return Value

Long — RGB color of the specified object.

Refer to file api32.txt for the current values for the COLOR_ constant values.




SetSysColors

VB Declaration

Code:
Declare Function SetSysColors& Lib "user32" (ByVal nChanges As Long, lpSysColor _
As Long, lpColorValues As Long)
Description

Sets the color of the specified Windows display object.

Parameter Type/Description
nChanges Long—Number of objects to change.
lpSysColor Long—Passed by reference. This is the first element in an integer array with nChanges elements. Each entry contains a constant specifying a Windows display object. Refer to the GetSysColors function for a complete list of objects whose colors may be set.
lpColorValues Long—Passed by reference. This is the first element in a long array of RGB values that will be used to set the colors of the objects in the lpSysColor array.
 
Thanks for the reply but, I'm not managing to work with this. When I do something like:

vari = GetSysColor(COLOR_MENU)

GetSysColor will allways return the same value no matter wich constant I use... and by the way lets say I want to change the color of a button I would only need to do:

cmdbut.Backcolor = GetSysColor(COLOR_MENU) 'for example

or do I need to convert the value I get to any other type?

I only need to declare the GetSysColor function right? Or do I need to reference any other thing?
Maybe I'm missing something out?

 
If all you are doing is trying to get hold of the system colours so that you can then apply them to controls on your form then you can skip the API stuff altogether, by using the builtin system colour constants:


Picture1.BackColor=vbActiveTitleBar

In most cases you can derive the VB constant name from the API constants by replacing 'COLOR_' with 'vb'. Or you can look them up in the object browser
 
Thanx that was just what I was looking for, everything works perfect now :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top