Visual Foxpro 9 uses GDIPlus to handle certain kinds of image files, such as JPG, GIF. Because the ability to decode image formats is now centralized in the operating system, VFP can take advantage of OS updates to file formats as well as other formats like WMF.
Sometimes, GDIPlus is just used to read the image files and the rendering is done by VFP. For some formats (such as animated GIFs or images with alpha blend (transparency)), GDIPlus is used to draw the image as well. Because VFP caches some images as “resources”, interesting problems can arise.
The code below creates a file called temp.prg that creates a form with an image control showing an animated GIF It then builds an APP file that embeds the GIF file directly internally and runs the code. If you run the program, you see the animated GIF on a form. Close the form and try to run the program again, and VFP hangs in an infinite loop trying to close a file handle for the GIF file that’s inside the APP.
The GIF is a cached image resource that GDIPlus still holds. Simple fix: it can be released via the CLEAR RESOURCE line.
(You can use this animated GIF as a sample )
#define TESTGIF “d:\monster.gif”
TEXT TO ctemp noshow && create a string with a few lines of code
PUBLIC x as Form
x.addobject(“img”,”image”) && add an image control and call it “img”
STRTOFILE(ctemp,”temp.prg”) && save as a file on disk
BUILD PROJECT temp FROM temp && build a project
MODIFY PROJECT temp nowait && add the GIF to the project so it’s embedded inside the target APP, EXE ,or DLL
*CLEAR RESOURCES TESTGIF && this line will fix the problem
BUILD APP temp FROM temp && build the APP (or exe)
DO temp && do the APP (or exe)