Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Download Visual Studio Add-In

GetSysColor (user32)
 
.
Summary

C# Signature:

[DllImport("user32.dll")]
static extern uint GetSysColor(int nIndex);

VB .NET Signature:

<DllImport("user32.dll")> _
<DllImport("user32.dll"> _
Public Shared Function GetSysColor(ByVal nIndex As Integer) As Integer
' Use nIndex = 1 to get Desktop color
End Function

User-Defined Types:

None.

Notes:

You can also use the COLOR_ constants as the index.

Tips & Tricks:

Here's which color corresponds to what in winuser.h

SystemColors.ScrollBar CTLCOLOR_MSGBOX, COLOR_SCROLLBAR
SystemColors.Desktop CTLCOLOR_EDIT, COLOR_BACKGROUND, COLOR_DESKTOP
SystemColors.ActiveCaption CTLCOLOR_LISTBOX, COLOR_ACTIVECAPTION
SystemColors.InactiveCaption CTLCOLOR_BTN, COLOR_INACTIVECAPTION
SystemColors.Menu CTLCOLOR_DLG, COLOR_MENU
SystemColors.Window CTLCOLOR_SCROLLBAR, COLOR_WINDOW
SystemColors.WindowFrame CTLCOLOR_STATIC, COLOR_WINDOWFRAME
SystemColors.MenuText CTLCOLOR_MAX, COLOR_MENUTEXT
SystemColors.WindowText COLOR_WINDOWTEXT
SystemColors.ActiveCaptionText COLOR_CAPTIONTEXT
SystemColors.ActiveBorder COLOR_ACTIVEBORDER
SystemColors.InactiveBorder COLOR_ACTIVEBORDER
SystemColors.AppWorkspace COLOR_APPWORKSPACE
SystemColors.Highlight COLOR_HIGHLIGHT
SystemColors.HighlightText COLOR_HIGHLIGHTTEXT
SystemColors.ButtonFace COLOR_BTNFACE, COLOR_3DFACE
SystemColors.ControlDark COLOR_BTNSHADOW
SystemColors.GrayText COLOR_GRAYTEXT
SystemColors.ControlText COLOR_BTNTEXT
SystemColors.InactiveCaptionText COLOR_INACTIVECAPTIONTEXT
SystemColors.ControlLightLight COLOR_BTNHIGHLIGHT, COLOR_3DHIGHLIGHT, COLOR_3DHILIGHT, COLOR_BTNHILIGHT
SystemColors.ControlDarkDark COLOR_3DSHADOW, COLOR_3DDKSHADOW
SystemColors.ControlLight COLOR_3DLIGHT
SystemColors.InfoText COLOR_INFOTEXT
SystemColors.Info COLOR_INFOBK
SystemColors.HotTrack COLOR_HOTLIGHT
SystemColors.GradientActiveCaption COLOR_GRADIENTACTIVECAPTION
SystemColors.GradientInactiveCaption COLOR_GRADIENTINACTIVECAPTION
SystemColors.MenuHighlight COLOR_MENUHILIGHT
SystemColors.MenuBar COLOR_MENUBAR

Sample Code:

VB.NET example
'Get the Desktop background color
Dim i as Integer = GetSysColor(1)
'GetSysColor returns in BGR byte order NOT RGB
Dim colorDT as Color = Color.FromARGB(i and &HFF, (i and &HFF00) >> 8, (i and &HFF0000) >> 16)

Alternative Managed API:

VB.NET
Dim colorDT as Color = SystemColors.Desktop
'Any other System color can be returned - See SystemColors class

Documentation
GetSysColor on MSDN

Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

 
Access PInvoke.net directly from VS:
Terms of Use
Edit This Page
Find References
Show Printable Version
Revisions