⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 caption.cpp

📁 一个完整的数字硬盘录像机系统软件
💻 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); 
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -