"Screen Capture and File Format"

I basically need an example of code that will “grab” the frame that is currently displayed on the screen and write it out to a file. The ultimate goal is to be able to grab a series of frames that are being simulated on the screen, save them to files, create a playback tool, and then use the playback tool to recreate the “movie” effect.
Right now, I run a simulation that consists of multiple frames (comes to the screen as an animation) and I am looking to be able to basically record this simulation (in separate frame files) to be played back identically as it was the first time at a later date.
I am open to any suggestions b/c I may be looking at this problem from the wrong angle. I hope that someone can help as soon as possible!!!

nate.scuzzy.net has some screen capture code. Output is TGA but you could stitch in the format of your choice.