|
//////////////////////////////////////////////////////////////////////
// ColorSpy Copyright 2003 Tom Furuya
//
// Readers of this article may copy the code for use in developing their own applications.
// If the code is used in a commercial application, however, an acknolegement must
// be included in the following form:
// "Segment of the code (c) 2003 Tom Furuya for CodeProject.com"
//////////////////////////////////////////////////////////////////////
// SysColors.h: interface for the CSysColors class.
#if !defined(AFX_SYSCOLORS_H__28A71688_1A1F_40FD_AD2A_D4009D229DBB__INCLUDED_)
#define AFX_SYSCOLORS_H__28A71688_1A1F_40FD_AD2A_D4009D229DBB__INCLUDED_
#pragma once
#include "Duo.h"
#define SCT_ENTRY(type) \
{ type, _T(#type), 0, 0 }
#define theSystemColors CSysColors::GetSysColors()
//
// CSysColors - System Color utility class
//
class CSysColors
{
public:
typedef struct SysColor
{
int type;
TCHAR* name;
int nameLen; // for performance
COLORREF clr;
};
enum { INVALID_COLOR_TYPE = -1 };
static bool s_bStaticInit;
static int s_nMaxPatternLen;
static DuoT<bool, COLORREF> GetColorByName(const CString& name)
{
const DuoT<bool, COLORREF> InvalidColor = make_duo(false, 0);
const CString strColor = _T("COLOR_");
const int nMinLen = 6;
const int len = name.GetLength();
SysColor* pos = GetSysColors();
if (len <= nMinLen || s_nMaxPatternLen < len) return InvalidColor;
if (strColor != name.Left(nMinLen)) return InvalidColor;
while (pos->type != INVALID_COLOR_TYPE)
{
if (len == pos->nameLen && pos->name[nMinLen] == name[nMinLen])
{
if (name == pos->name)
return make_duo(true, pos->clr);
}
pos++;
}
return InvalidColor;
}
inline COLORREF GetSystemColor(int nIndex)
{
ATLASSERT(COLOR_SCROLLBAR <= nIndex && nIndex <= COLOR_MENUBAR);
ATLASSERT(nIndex != 25); // unused slot
return GetSysColors()[nIndex].clr;
}
static SysColor* const GetSysColors()
{
// There are about 30 different system color types as display aspects [WinUser.h].
static SysColor SysColors[] =
{
SCT_ENTRY(COLOR_SCROLLBAR), // Scroll bar color
SCT_ENTRY(COLOR_BACKGROUND), // Desktop color (same as COLOR_DESKTOP which sounds more descriptive)
SCT_ENTRY(COLOR_ACTIVECAPTION), // Color of the title bar for the active window (Color1)
SCT_ENTRY(COLOR_INACTIVECAPTION), // Color of the title bar for the inactive window
SCT_ENTRY(COLOR_MENU), // Menu background color
SCT_ENTRY(COLOR_WINDOW), // Window background color
SCT_ENTRY(COLOR_WINDOWFRAME), // Window frame color
SCT_ENTRY(COLOR_MENUTEXT), // Color of text on menus
SCT_ENTRY(COLOR_WINDOWTEXT), // Color of text in windows
SCT_ENTRY(COLOR_CAPTIONTEXT), // Color of text in caption, size box, and
// scroll arrow
SCT_ENTRY(COLOR_ACTIVEBORDER), // Border color of active window
SCT_ENTRY(COLOR_INACTIVEBORDER), // Border color of inactive window
SCT_ENTRY(COLOR_APPWORKSPACE), // Background color of multiple-document interface
// (MDI) applications
SCT_ENTRY(COLOR_HIGHLIGHT), // Background color of items selected in a control
SCT_ENTRY(COLOR_HIGHLIGHTTEXT), // Text color of items selected in a control
SCT_ENTRY(COLOR_BTNFACE), // Color of shading on the face of command buttons
SCT_ENTRY(COLOR_BTNSHADOW), // Color of shading on the edge of command buttons
SCT_ENTRY(COLOR_GRAYTEXT), // Grayed (disabled) text
SCT_ENTRY(COLOR_BTNTEXT), // Text color on push buttons
SCT_ENTRY(COLOR_INACTIVECAPTIONTEXT),// Color of text in an inactive caption
SCT_ENTRY(COLOR_BTNHIGHLIGHT), // Highlight color for 3-D display elements
#if(WINVER >= 0x0400)
SCT_ENTRY(COLOR_3DDKSHADOW), // Darkest shadow color for 3-D display elements
SCT_ENTRY(COLOR_3DLIGHT), // Second lightest 3-D color after 3DHighlight
SCT_ENTRY(COLOR_INFOTEXT), // Color of text in ToolTips
SCT_ENTRY(COLOR_INFOBK), // Background color of ToolTips
#endif /* WINVER >= 0x0400 */
{ 0, NULL, 0, 0 }, // 25 - no entry...
#if(WINVER >= 0x0500)
SCT_ENTRY(COLOR_HOTLIGHT),
SCT_ENTRY(COLOR_GRADIENTACTIVECAPTION), //Active Titlebar background color (color for Color2)
SCT_ENTRY(COLOR_GRADIENTINACTIVECAPTION),//Inactive Titlebar background color
#endif /* WINVER >= 0x0500 */
#if(WINVER >= 0x0501)
SCT_ENTRY(COLOR_MENUHILIGHT),
SCT_ENTRY(COLOR_MENUBAR),
#endif /* WINVER >= 0x0501 */
{ INVALID_COLOR_TYPE, NULL, 0, 0 }
};
if (s_bStaticInit) return SysColors;
// one time initialization
SysColor* pos = SysColors;
while (pos->type != INVALID_COLOR_TYPE)
{
pos->nameLen = lstrlen(pos->name);
if (s_nMaxPatternLen < pos->nameLen)
s_nMaxPatternLen = pos->nameLen;
pos->clr = GetSysColor(pos->type);
pos++;
}
// done
s_bStaticInit = true;
return SysColors;
}
};
__declspec(selectany) bool CSysColors::s_bStaticInit = false;
__declspec(selectany) int CSysColors::s_nMaxPatternLen = 0;
#endif // !defined(AFX_SYSCOLORS_H__28A71688_1A1F_40FD_AD2A_D4009D229DBB__INCLUDED_)
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Live (1994
"Throwing Copper" till 1999 "The Distance To Here") is one of his favorite bands.
After 9 years life in U.S, he lives in his hometown Yokohama, working in Automotive After-sales business.
He sometimes found himself drunk once in a while in Munich.
He has put the period to his windows development after writing first and last article about a light-weight memory program, called colorspy (which is amusingly running on his latest windows except for dual display support.)
He has a message to the WTL author, "you rock. you proved that WTL kicks ass, M*F*C". F, in the middle, always reminds him of somewhat different wording.
Time lapse
His codepen is live.copper. His main focus has changed to various web technologies, to build fastest EPC services for automotive clients instead of pharmaceutical ones.
Ironically, he has not yet been released from the chaotic Windows software development installations even though he is no longer programming for Windows but for server side development.
Ein Prosit, Ein Prosit! He is still with a company in Munich as he loves to help people all over the world who need to fix their cars.