www.pudn.com > glyphbutton_src.zip > GlyphButton.cpp


///////////////////////////////////////////////////////////////////////// 
// GlyphButton.cpp : implementation file 
 
 
#include "stdafx.h" 
#include "GlyphButton.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////// 
// CGlyphButton 
 
CGlyphButton::CGlyphButton() 
{ 
	memset(&m_lf, 0, sizeof(LOGFONT));       // zero out structure 
 
	m_lf.lfCharSet = DEFAULT_CHARSET; 
	m_lf.lfHeight = -30; 
	m_lf.lfWeight = FW_NORMAL; 
	lstrcpy(m_lf.lfFaceName, _T("WingDings")); 
 
	m_cGlyph = 0xB4; 
} 
 
void CGlyphButton::PreSubclassWindow()  
{ 
	CButton::PreSubclassWindow(); 
 
	ReconstructFont(); 
	SetWindowText(CString(m_cGlyph)); 
} 
 
CGlyphButton::~CGlyphButton() 
{ 
} 
 
 
BEGIN_MESSAGE_MAP(CGlyphButton, CButton) 
	//{{AFX_MSG_MAP(CGlyphButton) 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
void CGlyphButton::ReconstructFont() 
{ 
	m_font.DeleteObject(); 
	VERIFY(m_font.CreateFontIndirect(&m_lf)); 
 
	CButton::SetFont(&m_font, TRUE); 
} 
 
 
///////////////////////////////////////////////////////////////////////// 
// CGlyphButton message handlers 
 
void CGlyphButton::SetFont(LOGFONT* plf) 
{ 
	memcpy(&m_lf, plf, sizeof(LOGFONT)); 
	ReconstructFont(); 
} 
void CGlyphButton::SetFont(CFont* pFont) 
{ 
	pFont->GetLogFont(&m_lf); 
	ReconstructFont(); 
} 
 
 
void CGlyphButton::SetGlyphEx(LOGFONT* plf, int cGlyph) 
{ 
	SetFont(plf); 
	SetGlyph(cGlyph); 
} 
void CGlyphButton::SetGlyphEx(CFont* pFont, int cGlyph) 
{ 
	pFont->GetLogFont(&m_lf); 
	ReconstructFont(); 
 
	SetGlyph(cGlyph); 
} 
void CGlyphButton::SetGlyphEx(LONG lHeight, LONG lWeight, CString strFaceName, int cGlyph) 
{ 
	m_lf.lfHeight = lHeight; 
	m_lf.lfWeight = lWeight; 
	lstrcpy(m_lf.lfFaceName, strFaceName); 
	ReconstructFont(); 
 
	SetGlyph(cGlyph); 
} 
 
void CGlyphButton::SetGlyph(int cGlyph) 
{ 
	m_cGlyph = cGlyph; 
	SetWindowText(CString(m_cGlyph)); 
} 
 
void CGlyphButton::SetHeight(LONG lHeight) 
{ 
	int	nSize = abs(lHeight) * -1;	//ensure that I wind up with a neg value. 
 
	m_lf.lfHeight = lHeight; 
	ReconstructFont(); 
} 
 
void CGlyphButton::SetWeight(LONG lWeight) 
{ 
	m_lf.lfWeight = lWeight; 
	ReconstructFont(); 
} 
 
void CGlyphButton::SetCharSet(BYTE bCharSet) 
{ 
	m_lf.lfCharSet = bCharSet; 
	ReconstructFont(); 
} 
 
 
void CGlyphButton::SetFaceName(CString strFaceName) 
{ 
	lstrcpy(m_lf.lfFaceName, strFaceName); 
	ReconstructFont(); 
} 
 
void CGlyphButton::SetButtonType(int nType) 
{ 
	ASSERT((nType >= BTN_DELETE) && (nType <= BTN_EDIT)); 
 
	m_lf.lfCharSet = SYMBOL_CHARSET; 
	m_lf.lfHeight = -22; 
	m_lf.lfWeight = FW_NORMAL; 
	lstrcpy(m_lf.lfFaceName, _T("WingDings")); 
 
	if(nType == BTN_DELETE) 
		SetGlyph(0xFB ); 
	else if(nType == BTN_EDIT) 
		SetGlyph(0xFC ); 
 
	ReconstructFont(); 
}