[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.drawing

Flicker free solution in GDI+ does not work

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
1 Answer

Eric Renken

10/12/2004 6:04:00 PM

0

You need to enable double buffering, check this article out. it is doing it
for a form, but it is the same concept.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformscontrolclasssetstyl...

This worked for me for a C# user control I created.

--
Eric Renken
Demiuirge Software LLC
http://www.d...


"Nuno Esculcas" <nesculcas@hotmail.com> wrote in message
news:38f0f14e.0410120349.76888160@posting.google.com...
> 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