15,978
社区成员
发帖
与我相关
我的任务
分享
void CTextScroller::OnPaint()
{
KillTimer(0);
CPaintDC dc(this); // device context for painting
DrawBkGround(&dc);
SetTimer(0,100,NULL);
}
void CTextScroller::DrawBkGround(CDC *pDC,CRect InvalidRect)
{
CRect rectClient;
GetClientRect(rectClient);
if(InvalidRect == CRect(0,0,0,0))
InvalidRect = rectClient;
if(m_bFirstTime)
{
if(m_Lines.GetCount())
{
POSITION pos = m_Lines.GetHeadPosition();
Line *_line = NULL;
int offset = rectClient.bottom;
CFont *pOldFont = pDC->SelectObject(&m_font);
CSize size = pDC->GetTextExtent(_T("TEST"));
pDC->SetBkMode(TRANSPARENT);
pDC->SelectObject(pOldFont);
while(pos)
{
_line = m_Lines.GetNext(pos);
if(_line)
{
_line->pos = offset;
_line->Initpos = offset;
offset += size.cy + 1;
}
}
m_bFirstTime = 0;
}
}
pDC->FillSolidRect(&InvalidRect,m_BkColor);
}
void CTextScroller::OnTimer(UINT nIDEvent)
{
if(nIDEvent == 0)
{
MoveTextToTheTop();
}
CStatic::OnTimer(nIDEvent);
}
void CTextScroller::MoveTextToTheTop()
{
int count = m_Lines.GetCount();
if(!count)
return;
CDC *pDC = GetDC();
CRect rectClient;
GetClientRect(rectClient);
CFont *pOldFont = pDC->SelectObject(&m_font);
int iOldMode = pDC->SetBkMode(TRANSPARENT);
COLORREF col = pDC->SetTextColor(m_TextColor);
CSize size = pDC->GetTextExtent(_T("TEST"));
Line *_line = NULL;
POSITION pos = m_Lines.GetHeadPosition();
int nIndex = -1;
while(pos)
{
_line = m_Lines.GetNext(pos);
nIndex++;
if(!_line)
return;
if(_line->bDecrease)
(_line->pos)--;
if(_line->pos < 0)
{
DrawBkGround(pDC,CRect(0,_line->pos - 1,rectClient.right,_line->pos + size.cy - 1));
_line->pos = _line->Initpos;
if(nIndex == m_Lines.GetCount()-1)
{
pos = m_Lines.GetHeadPosition();
while(pos)
{
_line = m_Lines.GetNext(pos);
_line->bDecrease = TRUE;
}
break;
}
else
_line->bDecrease = FALSE;
continue;
}
if(_line->pos > rectClient.bottom - size.cy)
continue;
DrawBkGround(pDC,CRect(0,_line->pos - 1,rectClient.right,_line->pos + size.cy + 1));
pDC->DrawText(_line->strLine,CRect(0,_line->pos,rectClient.right,_line->pos + size.cy),DT_CENTER);
}
pDC->SetBkMode(TRANSPARENT );
pDC->SelectObject(pOldFont);
pDC->SetTextColor(col);
//Clean the top of the window
DrawBkGround(pDC,CRect(0,0,rectClient.right,size.cy));
ReleaseDC(pDC);
}