Click here to Skip to main content
15,885,683 members
Articles / Desktop Programming / MFC

XTrueColorToolBar - True-color toolbar with support for Office-style color button

Rate me:
Please Sign up or sign in to vote.
4.69/5 (20 votes)
10 Jan 2008CPOL5 min read 72.7K   4.2K   63  
XTrueColorToolBar is an MFC class based on CToolBar that provides support for true-color bitmaps, with optional support for an Office-style color picker button.
// XTrueColorToolBar.h  Version 1.0 - article available at www.codeproject.com
//
// Author:  Hans Dietrich
//          hdietrich@gmail.com
//
// License:
//     This software is released into the public domain.  You are free to use
//     it in any way you like, except that you may not sell this source code.
//
//     This software is provided "as is" with no expressed or implied warranty.
//     I accept no liability for any damage or loss of business that this 
//     software may cause.
//
///////////////////////////////////////////////////////////////////////////////

#ifndef XTRUECOLORTOOLBAR_H
#define XTRUECOLORTOOLBAR_H

#ifndef __AFXWIN_H__
	#error include 'stdafx.h' precompiled header before including this file
#endif

//=============================================================================
class CXTrueColorToolBar : public CToolBar
//=============================================================================
{
//=============================================================================
// Construction
//=============================================================================
public:
	CXTrueColorToolBar();

//=============================================================================
// Attributes
//=============================================================================
public:
	COLORREF	GetBackgroundColor()				{ return m_crBackgroundColor; }
	void		SetBackgroundColor(COLORREF rgb)	{ m_crBackgroundColor = rgb; }
	void		GetImageDimensions(int& nWidth, int& nHeight)
				{ nWidth = m_nImageWidth; nHeight = m_nImageHeight; }
	void		SetImageDimensions(int nWidth, int nHeight)
				{ m_nImageWidth = nWidth; m_nImageHeight = nHeight; }
	COLORREF	GetMaskColor()						{ return m_crMaskColor; }
	void		SetMaskColor(COLORREF rgb)			{ m_crMaskColor = rgb; }

//=============================================================================
// Operations
//=============================================================================
public:
	void AttachToolbarImages(UINT nBitmapId, int nNumImages, int nToolbar);	// 0 = normal, 1 = disabled, 2 = hot
	BOOL CreateTemplate(COLORREF rgb);
	COLORREF GetColorButton() { return m_crCurrentColor; }
	void SetColorButton(UINT nCommandId, COLORREF rgb);

//=============================================================================
// Implementation
//=============================================================================
protected:
	CImageList	m_TrueColorImages;		// toolbar image list
	CImageList	m_ImageTemplate;		// copy of initial toolbar image list 
	int			m_nNumImages;			// number of images in toolbar bitmap
	int			m_nImageWidth;			// width of a single image in toolbar bitmap
	int			m_nImageHeight;			// height of a single image in toolbar bitmap
	UINT		m_nToolBarBitDepth;		// currently must be ILC_COLOR24;
	COLORREF	m_crCurrentColor;		// current color of bar under "A" on color button
	COLORREF	m_crMaskColor;			// mask color of bar under "A" on color button
	COLORREF	m_crBackgroundColor;	// background color of buttons in 
										// toolbar resource

	BOOL GetBitmapFromImageList(CBitmap& bm, CImageList* pList);
	int GetImageIndex(UINT nCommandId);
	void MakeToolbarImageList(UINT inBitmapID, 
							 CImageList& outImageList);
	void ReplaceBackgroundColor(CBitmap& bm, COLORREF OldColor, COLORREF NewColor);
	void ReplaceMaskColor(CBitmap& bm1,			// toolbar images
						  CBitmap& bm2,			// image mask
						  COLORREF OldColor, 
						  COLORREF NewColor);
};

#endif //XTRUECOLORTOOLBAR_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) Hans Dietrich Software
United States United States
I attended St. Michael's College of the University of Toronto, with the intention of becoming a priest. A friend in the University's Computer Science Department got me interested in programming, and I have been hooked ever since.

Recently, I have moved to Los Angeles where I am doing consulting and development work.

For consulting and custom software development, please see www.hdsoft.org.






Comments and Discussions