Click here to Skip to main content
15,892,517 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 241K   6.8K   63  
Simple customised Window captions, including multi-line captions
#include "StdAfx.h"
#include "SystemCaptionFont.h"

//////////////////////////////////////////////////////////////////////////////////////////
// CSystemCaptionFont provides self-contained access to the default system caption font.
//
// operator() returns a CFont pointer to a font created on demand.
//
// The destructor deletes the font object attached to CSystemCaptionFont.
//

///////////
// Destructor deletes any font object associated with CFont member.
//
CSystemCaptionFont::~CSystemCaptionFont() 
{ 
	if (m_Font.m_hObject) 
		m_Font.DeleteObject(); 
}

/////////////
// Returns a lazy-created CFont*
//
CFont* CSystemCaptionFont::operator()()
{
	if (!m_Font.m_hObject)  
		CreateFont();

	return &m_Font;
}

/////////////////
// Creates a caption font using the system caption defaults
//
void CSystemCaptionFont::CreateFont()
{
	NONCLIENTMETRICS ncm;
    memset(&ncm, 0, sizeof(ncm));
    ncm.cbSize = sizeof(ncm);
    SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, &ncm, 0);

	if (m_Font.m_hObject)
		m_Font.DeleteObject();
	
    m_Font.CreateFontIndirect(&ncm.lfCaptionFont);
} 

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