www.pudn.com > 2007112823521925.rar > Caption.cpp


// Caption.cpp : implementation file 
///////////////////////////////////////////////////////////////////////////// 
 
#include "stdafx.h" 
#include "Caption.h" 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// CCaption 
 
CCaption::CCaption() 
{ 
	m_clrFont		= GetCurrentColor(COLOR_RED); 
	m_hIcon			= NULL; 
	LOGFONT LogFont; 
    LogFont.lfHeight=16;//12ºÅ   
    LogFont.lfWidth=0; 
    LogFont.lfEscapement=0; 
    LogFont.lfOrientation=0; 
    LogFont.lfWeight=400; 
    LogFont.lfItalic=0; 
    LogFont.lfUnderline=0; 
    LogFont.lfStrikeOut=0; 
    LogFont.lfCharSet=134; 
    LogFont.lfOutPrecision=3; 
    LogFont.lfClipPrecision=2; 
    LogFont.lfQuality=0; 
    LogFont.lfPitchAndFamily=1; 
	strcpy(LogFont.lfFaceName,"ËÎÌå"); 
	m_Font.CreateFontIndirect(&LogFont); 
	m_pFont=NULL; 
} 
 
CCaption::~CCaption() 
{ 
} 
 
BEGIN_MESSAGE_MAP(CCaption, CStatic) 
	//{{AFX_MSG_MAP(CCaption) 
	ON_WM_PAINT() 
	ON_WM_SYSCOLORCHANGE() 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CCaption message handlers 
void CCaption::SetFontColor(COLORREF clr) 
{ 
	m_clrFont = clr; 
} 
void CCaption::SetCaptionFont(CFont* pFont) 
{ 
	m_pFont = pFont; 
} 
 
void CCaption::SetCaptionText(LPCTSTR lpszString, HICON hIcon) 
{ 
	SetWindowText(lpszString); 
	m_hIcon = hIcon; 
	Invalidate(); 
} 
 
void CCaption::OnPaint() 
{ 
	CPaintDC dc(this); // device context for painting 
 
	// Get the client rect for this control. 
	CRect rc; 
	GetClientRect(&rc); 
	dc.SetBkMode(TRANSPARENT); 
	DrawRectangle(&dc,rc,1,COLOR_BEIGE,COLOR_BEIGE); 
	PaintBanner(rc, &dc); 
} 
 
void CCaption::PaintBanner(CRect rect, CDC *pDC) 
{ 
	pDC->SetTextColor(m_clrFont); 
	// Get the window text for this control. 
	CString strText; 
	GetWindowText(strText); 
 
	rect.DeflateRect(2,2); 
	rect.left += 8; 
 
	// Shuffle fonts and paint the text. 
	CFont* oldFont = pDC->SelectObject((m_pFont == NULL)?&m_Font:m_pFont); 
	pDC->DrawText(strText, rect, DT_LEFT |DT_WORDBREAK   );// DT_VCENTER | DT_SINGLELINE); 
	pDC->SelectObject(oldFont); 
 
	if (m_hIcon!=NULL) 
	{ 
		int cx = ::GetSystemMetrics(SM_CXSMICON); 
		int cy = ::GetSystemMetrics(SM_CYSMICON); 
		int top = (rect.Height()-cy)/2+2; 
 
		::DrawIconEx(pDC->GetSafeHdc(), 
			rect.right-21, top, 
			m_hIcon, cx, cy, NULL, (HBRUSH)NULL, DI_NORMAL);  
	} 
}