Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to detect screen refresh....?

Status
Not open for further replies.

onrdbandit

Programmer
Mar 12, 2003
145
US
howdy,

I am working on an app that somes physics problems i.e. projectile trajectory etc. and I want to generate simple animations from these calculations.

I have the necessary code to draw the frames to a TCanvas, but I need to detect the screen refreshing, so I can copy the buffered images to the visible TCanvas without "tearing" the images.

Without properly timing the TCanvas->Refresh() function calls, the animation is impossible to see.

thanks in advance
onrdbandit
 
What you may be seeing is a Borland Booboo. In their attempt at making the programming interface user friendly, they assume a lot of things, and one of those is in the Microsoft function call InvalidateRect(). There is a parameter called bErase that the TCanvas automatically fills in as true. You want to say false. What it does is erases the background, then redraws the canvas, creating a blinking-like animation.

To solve this, override the Invalidate function and maybe the Update function? I can't remember, I have that info at work, so I'll post it tomorrow. Anyway, you force call InvalidateRect and set that parameter to false. But in your paint function you still double buffer:

void __fastcall Paint(void)
{
static Graphics::TBitmap *BackBuffer = new Graphics::TBitmap();

TRect Rect = Rect(0, 0, Width, Height);
BackBuffer->Width = Width;
BackBuffer->Height = Height;
BackBuffer->Canvas->FillRect(Rect);
BackBuffer->Canvas->LineTo(...);
BackBuffer->Canvas->Ellipse(...);
BackBuffer->Canvas->AllDrawingFunctions(...);

Canvas->Draw(0, 0, BackBuffer);
}

Hope that helps,
Chris
 
Best way to do it is to use Device-Dependent-Bitmap. If you want to know more mail me at dominochmiel@interia.pl
 
Nevermind, you don't need to override anything but the Paint method. Just don't call it's ansestor paint method. Be sure that your backbuffer is cleared out too.

Chris
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top