Results 1 to 4 of 4

Thread: How to get System Color? [RESOLVED]

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Dec 2002
    Location
    Malaysia
    Posts
    224

    How to get System Color? [RESOLVED]

    Does anyone know how to check colors in which the system is configured to use for windows , etcin VB?

    For example, the preference window color of XP and win2k is totally different, in my VB program i can't hardcode any of my windows to any colow if it were to be set enabled. How do i read preference colow and then set it accordingly in my program?

    Thank you
    leng wai
    Last edited by lengwai; Mar 11th, 2003 at 12:24 AM.

  2. #2
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926
    If you just want to set a backcolor or forecolor property, you can use the color constants in code like this:
    Me.BackColor = vbButtonFace
    or you can set it at design time (use the colors from the system tab in the property window).


    These are the other constants (From MSDN):
    Constant Value Description
    vbScrollBars &H80000000 Scroll bar color
    vbDesktop &H80000001 Desktop color
    vbActiveTitleBar &H80000002 Color of the title bar for the active window
    vbInactiveTitleBar &H80000003 Color of the title bar for the inactive window
    vbMenuBar &H80000004 Menu background color
    vbWindowBackground &H80000005 Window background color
    vbWindowFrame &H80000006 Window frame color
    vbMenuText &H80000007 Color of text on menus
    vbWindowText &H80000008 Color of text in windows
    vbTitleBarText &H80000009 Color of text in caption, size box, and scroll arrow
    vbActiveBorder &H8000000A Border color of active window
    vbInactiveBorder &H8000000B Border color of inactive window
    vbApplicationWorkspace &H8000000C Background color of multiple-document interface (MDI) applications
    vbHighlight &H8000000D Background color of items selected in a control
    vbHighlightText &H8000000E Text color of items selected in a control
    vbButtonFace &H8000000F Color of shading on the face of command buttons
    vbButtonShadow &H80000010 Color of shading on the edge of command buttons
    vbGrayText &H80000011 Grayed (disabled) text
    vbButtonText &H80000012 Text color on push buttons
    vbInactiveCaptionText &H80000013 Color of text in an inactive caption
    vb3DHighlight &H80000014 Highlight color for 3D display elements
    vb3DDKShadow &H80000015 Darkest shadow color for 3D display elements
    vb3DLight &H80000016 Second lightest of the 3D colors after vb3Dhighlight
    vb3DFace &H8000000F Color of text face
    vb3Dshadow &H80000010 Color of text shadow
    vbInfoText &H80000017 Color of text in ToolTips
    vbInfoBackground &H80000018 Background color of ToolTips
    Frans

  3. #3
    Fanatic Member laserman's Avatar
    Join Date
    Jan 2002
    Location
    Wales U.K
    Posts
    775
    This may help you:-

    VB Code:
    1. Private Declare Function SetSysColors Lib "user32" (ByVal nChanges As Long, lpSysColor As Long, lpColorValues As Long) As Long
    2. Private Declare Function GetSysColor Lib "user32" (ByVal nIndex As Long) As Long
    3. Const COLOR_SCROLLBAR = 0 'The Scrollbar colour
    4. Const COLOR_BACKGROUND = 1 'Colour of the background with no wallpaper
    5. Const COLOR_ACTIVECAPTION = 2 'Caption of Active Window
    6. Const COLOR_INACTIVECAPTION = 3 'Caption of Inactive window
    7. Const COLOR_MENU = 4 'Menu
    8. Const COLOR_WINDOW = 5 'Windows background
    9. Const COLOR_WINDOWFRAME = 6 'Window frame
    10. Const COLOR_MENUTEXT = 7 'Window Text
    11. Const COLOR_WINDOWTEXT = 8 '3D dark shadow (Win95)
    12. Const COLOR_CAPTIONTEXT = 9 'Text in window caption
    13. Const COLOR_ACTIVEBORDER = 10 'Border of active window
    14. Const COLOR_INACTIVEBORDER = 11 'Border of inactive window
    15. Const COLOR_APPWORKSPACE = 12 'Background of MDI desktop
    16. Const COLOR_HIGHLIGHT = 13 'Selected item background
    17. Const COLOR_HIGHLIGHTTEXT = 14 'Selected menu item
    18. Const COLOR_BTNFACE = 15 'Button
    19. Const COLOR_BTNSHADOW = 16 '3D shading of button
    20. Const COLOR_GRAYTEXT = 17 'Grey text, of zero if dithering is used.
    21. Const COLOR_BTNTEXT = 18 'Button text
    22. Const COLOR_INACTIVECAPTIONTEXT = 19 'Text of inactive window
    23. Const COLOR_BTNHIGHLIGHT = 20 '3D highlight of button
    24. Const COLOR_2NDACTIVECAPTION = 27 'Win98 only: 2nd active window color
    25. Const COLOR_2NDINACTIVECAPTION = 28 'Win98 only: 2nd inactive window color
    26. Private Sub Form_Load()
    27.     'KPD-Team 1998
    28.     'URL: [url]http://www.allapi.net/[/url]
    29.     'E-Mail: [email][email protected][/email]
    30.     'Get the caption's active color
    31.     col& = GetSysColor(COLOR_ACTIVECAPTION)
    32.     'Change the active caption's color to red
    33.     t& = SetSysColors(1, COLOR_ACTIVECAPTION, RGB(255, 0, 0))
    34.     MsgBox "The old title bar color was" + Str$(col&) + " and is now" + Str$(GetSysColor(COLOR_ACTIVECAPTION))
    35. End Sub

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Dec 2002
    Location
    Malaysia
    Posts
    224
    Thanks a lot man .. i'm sure this rest my case for now.

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