nesculcas
10/12/2004 11:49:00 AM
Hello,
I'm working on VC7 and i'm trying to make a simple animation that
have an image in the background and the animation is a text that is
scrolling from right to left. I'm doing this in GDI+ and i'm using the
technique DrawCachedBitmap to avoid the flicker, but i'm still getting
the flicker.
My question is what i'm doing wrong? or this technique is not valid?
(only for better understanding i'm showing the code)
//On the beginning i'm loading the background image into memory, and
start the position of the text
m_pcMemBitmap = Gdiplus::Bitmap::FromFile(strLastImageLoad);
m_nPos=1024;
//Then i have a function to draw the animation
void CChildView::DrawImage(HDC hdc)
{
if(m_pcMemBitmap)
{
Graphics graphics(hdc);
int nHeight = m_pcMemBitmap->GetHeight();
int nWidth = m_pcMemBitmap->GetWidth();
//here i make a copy of the image
PixelFormat pixFrmt = m_pcMemBitmap->GetPixelFormat();
Bitmap* bTemp = (Bitmap*)m_pcMemBitmap->Clone(
0,
0,
nWidth,
nHeight,
pixFrmt);
if( bTemp == NULL )
{
_ASSERTE(bTemp);
return;
}
//now i draw the text in diferent positions
Graphics grFrBk(bTemp);
PointF p1((REAL)m_nPos,(REAL)0);
grFrBk.DrawString(_T("Something to see the text scrolling..."),
m_pcMemBitmap->GetWidth(),
m_pcFont,
p1,
m_pcFontColor);
CachedBitmap cCachedBitmap(bTemp,&graphics);
graphics.DrawCachedBitmap(&cCachedBitmap,0,0);
delete bTemp;
}
}
//On my Paint and backgroud functions i do this
void CChildView::OnPaint()
{
CPaintDC dc(this);
DrawImage(dc.m_hDC);
}
BOOL CChildView::OnEraseBkgnd(CDC* pDC)
{
return TRUE;
}
//Then the animation is updated in one timer that i set
(SetTimer(ID_TM_BETWEEN_REFRESHES, 30, 0);)
void CChildView::OnTimer(UINT nIDEvent)
{
if( nIDEvent == ID_TM_BETWEEN_REFRESHES)
{
m_nPos-=5;
CClientDC dc(this);
DrawImage(dc.m_hDC);
}
CWnd::OnTimer(nIDEvent);
}
Then i get the text moving yes but with a slighty flickering... what
i'm doing wrong? it's another way of doing this? the GDI+ is not so
good for this?
Thanks for the attencion
Nuno