Click here to Skip to main content
15,884,298 members
Articles / Desktop Programming / MFC

ClassLib, A C++ class library

Rate me:
Please Sign up or sign in to vote.
4.80/5 (32 votes)
25 May 2005CPOL8 min read 399.4K   11.5K   141  
C++ class library.
#ifndef _XPCOLORS_H_
#define _XPCOLORS_H_
//
// xpcolors.h
//
// (C) Copright 2002 Jan van den Baard.
//     All Rights Reserved.
//

#include "../standard.h"
#include "color.h"

// A simple class which will hold the colors necessary
// to render the Office XP style menus etc.
class ClsXPColors
{
public:
	// Color indexes.
	enum
	{
		XPC_OUTER_SELECTION = 0,	// Outside selection rectangle.
		XPC_INNER_SELECTION = 1,	// Inside selection rectangle.
		XPC_OUTER_CHECKED = 2,		// Outside checkmark rectangle.
		XPC_INNER_CHECKED = 3,		// Inside checkmark rectangle (unselected).
		XPC_INNER_CHECKED_SELECTED = 4,	// Inside checkmark rectangle (selected).
		XPC_IMAGE_BACKGROUND = 5,	// Image background area.
		XPC_IMAGE_DISABLED = 6,		// Image disabled color.
		XPC_IMAGE_SHADOW = 7,		// Shadow image color.
		XPC_TEXT = 8,			// Text color.
		XPC_TEXT_DISABLED = 9,		// Text color disabled.
		XPC_TEXT_BACKGROUND = 10,	// Background text.
		XPC_SEPARATOR = 11,		// Seperator.
		XPC_SIZEOF = 12
	};

	// Construction/destruction.
	ClsXPColors() { CreateColorTable(); }
	virtual ~ClsXPColors() {;}

	// Implementation.
	void CreateColorTable()
	{
		// Selection rectangle.
		ClsColor color( ::GetSysColor( COLOR_HIGHLIGHT ));
		m_crColorTable[ XPC_OUTER_SELECTION ] = color;
		color.LightenColor( 0.71, 0.71, 0.71 );
		m_crColorTable[ XPC_INNER_SELECTION ] = color;

		// Menu background.
		color.SetRGB( ::GetSysColor( COLOR_BTNFACE ));
		color.LightenColor( 0.2, 0.2, 0.2 );
		m_crColorTable[ XPC_IMAGE_BACKGROUND ] = color;
		color.LightenColor( 0.83, 0.83, 0.83 );
		m_crColorTable[ XPC_TEXT_BACKGROUND ] = color;

		// Checkmark rectangle.
		m_crColorTable[ XPC_OUTER_CHECKED ] = m_crColorTable[ XPC_OUTER_SELECTION ];
		color.SetRGB( m_crColorTable[ XPC_OUTER_SELECTION ] );
		color.LightenColor( 0.5, 0.5, 0.5 );
		m_crColorTable[ XPC_INNER_CHECKED_SELECTED ] = color;
		color.SetRGB( m_crColorTable[ XPC_IMAGE_BACKGROUND ] );
		color.LightenColor( 0.3, 0.3, 0.5 );
		m_crColorTable[ XPC_INNER_CHECKED ] = color;

		// Images.
		m_crColorTable[ XPC_IMAGE_DISABLED ] = ::GetSysColor( COLOR_GRAYTEXT );
		color.SetRGB( m_crColorTable[ XPC_OUTER_SELECTION ] );
		color.LightenColor( 0.3, 0.3, 0.3 );
		m_crColorTable[ XPC_IMAGE_SHADOW ] = color;

		// Text.
		m_crColorTable[ XPC_TEXT ] = ::GetSysColor( COLOR_MENUTEXT );
		color.SetRGB( ::GetSysColor( COLOR_GRAYTEXT )); 
		color.LightenColor( 0.3, 0.3, 0.3 );
		m_crColorTable[ XPC_TEXT_DISABLED ] = color;

		// Separator.
		m_crColorTable[ XPC_SEPARATOR ] = color;
	}

	// Obtain a color from the table.
	inline COLORREF GetXPColor( int nIndex ){ _ASSERT( nIndex >= 0 && nIndex <= 11 ); return m_crColorTable[ nIndex ]; }

protected:
	// Data.
	COLORREF	m_crColorTable[ XPC_SIZEOF ];
};
// Defined in application.cpp.
extern ClsXPColors XPColors;
#endif _XPCOLORS_H_

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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
Netherlands Netherlands
I have been programming for a hobby since 1985. I have started programming on the C= 64. After that I migrated to the C= Amiga which I traded in for a PC back in 1997 I believe. Back in 2000 I decided to lose a hobby and start developing software for a living.

Currently I am working mainly in developing software for building security and access control systems.

Comments and Discussions