📄 numbertext.cpp
字号:
// NumberText.cpp : implementation file
//
#include "stdafx.h"
#include "eBookBrow.h"
#include "NumberText.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CNumberText
CNumberText::CNumberText()
{
m_strText = CString(_T("当前还未打开相册"));
m_bkColor = RGB(255, 255, 255);
m_textColor = RGB(0,0, 255);
}
CNumberText::~CNumberText()
{
if(m_compDC.GetSafeHdc() != NULL)
{
m_compDC.DeleteDC();
}
if(m_bkDC.GetSafeHdc() != NULL)
{
m_bkDC.DeleteDC();
}
}
BEGIN_MESSAGE_MAP(CNumberText, CStatic)
//{{AFX_MSG_MAP(CNumberText)
ON_WM_PAINT()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CNumberText message handlers
BOOL CNumberText::Create(DWORD style, const RECT& rect, CWnd* pParentWnd, UINT ID)
{
BOOL Result;
Result = CStatic::Create(NULL, style, rect, pParentWnd, ID);
GetClientRect(m_Rect);
CPaintDC dc(this);
if(m_bkDC.GetSafeHdc() == NULL)
{
m_bkDC.CreateCompatibleDC(&dc);
m_bkBitmap.CreateCompatibleBitmap(&dc, m_Rect.Width(), m_Rect.Height());
m_bkDC.SelectObject(&m_bkBitmap);
}
if(m_compDC.GetSafeHdc() == NULL)
{
m_compDC.CreateCompatibleDC(&dc);
m_compBitmap.CreateCompatibleBitmap(&dc, m_Rect.Width(), m_Rect.Height());
m_compDC.SelectObject(&m_compBitmap);
}
DrawBK();
return Result;
}
void CNumberText::UpdateText(int num, int maxNum)
{
m_strText.Format(_T("第%d页/共%d页"), num, maxNum);
DrawNumText();
}
void CNumberText::DrawBK()
{
m_bkDC.FillSolidRect(&m_Rect, RGB(255, 255, 255));
m_compDC.BitBlt(0,0,m_Rect.Width(), m_Rect.Height(), &m_bkDC, 0,0, SRCCOPY);
DrawNumText();
}
void CNumberText::DrawNumText()
{
CFont font;
//font.CreateFont(50, 0, 0, 0, FW_BOLD, FALSE, FALSE, 0, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_SWISS, "Arial");
VERIFY(font.CreateFont(
20, // nHeight
8, // nWidth
0, // nEscapement
0, // nOrientation
FW_BOLD, // nWeight
FALSE, // bItalic
FALSE, // bUnderline
0, // cStrikeOut
ANSI_CHARSET, // nCharSet
OUT_DEFAULT_PRECIS, // nOutPrecision
CLIP_DEFAULT_PRECIS, // nClipPrecision
DEFAULT_QUALITY, // nQuality
DEFAULT_PITCH | FF_SWISS, // nPitchAndFamily
"Arial")); // lpszFacename
m_compDC.BitBlt(0,0,m_Rect.Width(), m_Rect.Height(), &m_bkDC, 0,0, SRCCOPY);
m_compDC.SetTextColor(m_textColor);
m_compDC.SelectObject(&font);
CSize strSize = m_compDC.GetTextExtent(m_strText);
m_compDC.TextOut((m_Rect.Width() - strSize.cx)/2,(m_Rect.Height() - strSize.cy)/2, m_strText);
font.DeleteObject();
Invalidate();
}
void CNumberText::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
dc.BitBlt(0, 0, m_Rect.Width(), m_Rect.Height(), &m_compDC, 0, 0, SRCCOPY);
// Do not call CStatic::OnPaint() for painting messages
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -