【VC开源代码栏目提醒】:以下是网学会员为您推荐的VC开源代码-DigitStatic.cpp,希望本篇文章对您学习有所帮助。
// DigitStatic.cpp : implementation file
//
#include "stdafx.h"
#include "DigitalStatic.h"
#include "DigitStatic.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDigitStatic
CDigitStatic::CDigitStatic()
{
m_DigitalLen = 6;
m_PerHeight = 34;
m_PerWidth = 26;
}
CDigitStatic::~CDigitStatic()
{
}
BEGIN_MESSAGE_MAP(CDigitStatic, CStatic)
//{{AFX_MSG_MAP(CDigitStatic)
ON_WM_PAINT()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDigitStatic message handlers
void CDigitStatic::OnPaint()
{
CPaintDC dc1(this); //device context for painting
SetRedraw(false);
CRect rect;
GetClientRect(rect);
CMemDC dc(&dc1,rect);
SetWindowText("");
CBitmap bmp;
bmp.LoadBitmap(IDB_BIGONE);
CDC memDC;
memDC.CreateCompatibleDC(&dc);
memDC.SelectObject(&bmp);
BITMAP bInfo;
bmp.GetBitmap(&bInfo);
int x = bInfo.bmWidth;
int y = bInfo.bmHeight;
int len = m_Text.GetLength();
for (int i = 0; i< m_DigitalLen; i++)
{
dc.BitBlt((i)*m_PerWidth,0,m_PerWidth,y,&memDC,10*m_PerWidth,0,SRCCOPY);
}
if (len>0 && len<m_DigitalLen)
{
for (int n = 0 ; n< len;n++)
{
char a= m_Text[len-n-1];
int b = atoi(&a);
dc.BitBlt((m_DigitalLen-n-1)*m_PerWidth,0,m_PerWidth,y,&memDC,(b)*m_PerWidth,0,SRCCOPY);
}
}
bmp.DeleteObject();
memDC.DeleteDC();
SetRedraw();
}
void CDigitStatic::SetText(LPCTSTR text)
{
m_Text = text;
RedrawWindow();
}
LPTSTR CDigitStatic::GetText()
{
return m_Text.GetBuffer(0);
}
void CDigitStatic::SubControl(UINT uID,CWnd* pParent)
{
SubclassDlgItem(uID,pParent);
CRect wRc;
GetWindowRect(wRc);
ScreenToClient(wRc);
MapWindowPoints(pParent,wRc);
wRc.right = wRc.left+m_DigitalLen*m_PerWidth;
wRc.bottom = wRc.top+m_PerHeight;
int width = m_DigitalLen*m_PerWidth;
MoveWindow(wRc);
}