Click here to Skip to main content
15,897,187 members
Articles / Multimedia / GDI

Custom Captions (Including Multi-line Captions)

Rate me:
Please Sign up or sign in to vote.
5.00/5 (9 votes)
15 Jul 2000CPOL 241.2K   6.8K   63  
Simple customised Window captions, including multi-line captions
#include "stdafx.h"
#include "CaptionBackground.h"
#include "AutoSelector.h"

//////////////////
// Helper to paint rectangle with a color.
//
CCaptionBackground::CCaptionBackground()
	:m_ActiveColor(-1), m_InactiveColor(-1)
{
}

CCaptionBackground::CCaptionBackground(const CCaptionBackground& cb)
	:m_ActiveColor(cb.m_ActiveColor), m_InactiveColor(cb.m_InactiveColor)
{
}

void CCaptionBackground::SetCustomColors(const CCaptionBackground& cb)
{
	SetActiveColor(cb.m_ActiveColor);
	SetInactiveColor(cb.m_InactiveColor);
}

void CCaptionBackground::SetCustomColors(COLORREF activeColor, COLORREF inactiveColor)
{
	SetActiveColor(activeColor);
	SetInactiveColor(inactiveColor);
}

void CCaptionBackground::SetActiveColor(COLORREF activeColor)
{
	m_ActiveColor = activeColor;
}

void CCaptionBackground::SetInactiveColor(COLORREF inactiveColor)
{
	m_InactiveColor = inactiveColor;
}

void CCaptionBackground::UseSystemColors()
{
	UseSystemActiveColor();
	UseSystemInactiveColor();
}

void CCaptionBackground::UseSystemActiveColor()
{
	m_ActiveColor = -1;
}

void CCaptionBackground::UseSystemInactiveColor()
{
	m_InactiveColor = -1;
}

boolean CCaptionBackground::IsUsingSystemColors()
{
	return m_ActiveColor == -1;
}

COLORREF CCaptionBackground::GetActiveColor()	const
{
	return m_ActiveColor == -1 ? GetSysColor(COLOR_ACTIVECAPTION) : m_ActiveColor;
}

COLORREF CCaptionBackground::GetInactiveColor() const
{
	return m_InactiveColor == -1 ? GetSysColor(COLOR_INACTIVECAPTION) : m_InactiveColor;
}

void CCaptionBackground::Paint(CDC* pDC, CSize paintArea, BOOL active)
{
	PaintRect(pDC, 0, 0, paintArea.cx, paintArea.cy, active ? GetActiveColor() : GetInactiveColor());
}

// Paint the color into the rectangle dimensions on the device context
void CCaptionBackground::PaintRect(CDC* pDC, int x, int y, int w, int h, COLORREF color)
{
	CBrush brush(color);
	AutoSelector a(pDC, &brush);
	pDC->PatBlt(x, y, w, h, PATCOPY);
}

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
Web Developer
United Kingdom United Kingdom
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions