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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

animated gif in visual foxpro form

ravicoder

Programmer
Apr 29, 2006
38
IN
Hi all

I'm trying to display an animated gif in a form when some data is being retrieved or when some processing is going on.

I've tried image control and webbrowser control, but I can't get the gif to animate. Any advice/sample code would be appreciated

thanks
 
Can you post your gif?

In VFP9 this should show the FoxPro logo morphing from new to old logo and back:
Code:
_screen.AddObject("image1","image")
_screen.image1.Picture=Home()+"GRAPHICS\GIFS\MORPHFOX.GIF"
_screen.image1.Visible = .t.
This doesn't require any code to start animating, just setting the picture. Obviously, this MORPHFOX.GIF is part of VFP9, not earlier versions,. But in principle I never needed any code to animate a GIF or even trigger starting the animation with any code, an animated GIF is just animated in itslef, so the OS rendering of it does that.
 
I know VFP9 introduced PNG rendering and SP1 or 2 fixed a bg with PNG transparency. That has nothing to do with GIF, but pretty sure VFP9s integration with GDI+ is best in the last version of it, if you use previous VFP versions, that might be the root cause of the GIF not working. If you could post your GIF, we'd not only see whether it animates in several browsers, I'd also verify whether it works in VFP9.
 
If VFP's animation fails, then get a copy of "gif89.dll" from the internet. (see here: https://www.vbforums.com/showthread.php?79007-gif89-dll
Copy that one file into \Windows\SYSWOW64, do a "REGSVR32 gif89.dll" from an administrative CMD in that directory.
Then in your form add an OleControl to your form and in the selection dialog choose "GIF89 CLASS".
Assign your giffile to the Filename property of that class:
Thisform.OleControl1.FileName = GetPict("gif")
 
Last edited:
This doesn't require any code to start animating, just setting the picture. Obviously, this MORPHFOX.GIF is part of VFP9, not earlier versions,. But in principle I never needed any code to animate a GIF or even trigger starting the animation with any code, an animated GIF is just animated in itslef, so the OS rendering of it does that.
The funny thing is I've never really thought about adding an animated GIF to a form, but I just tested it and tried two ways using the MORPHFOX.GIF file, and you are correct, it works perfectly using the built-in Image control in the latest VFP without needing anything else.

I tried it two ways... Once by adding a regular Image control from the Designer, then once by adding it to a Container programmatically in the Init.

I guess I noticed that older versions didn't support animation so I assumed the newer versions didn't support it and didn't try again until your post. Well done.
 
Well, putting an image control on a form and setting the Picture interactively (double click the picture property and pick the MORPHFOX.GIF from the file open dialog) it even animates in design mode immediately. I don't see it depend on how you set the picture.
 
Well, putting an image control on a form and setting the Picture interactively (double click the picture property and pick the MORPHFOX.GIF from the file open dialog) it even animates in design mode immediately. I don't see it depend on how you set the picture.
I tend to place 99% of images directly from the IDE, but there are times where the only useful way is to do it in the Init code, such as when the filename is taken from the data itself, such as a customer's logo, or in cases where I want the logo to visually reflect the status of a field. For example, drawing attention to an inactive customer, or a customer who is COD vs ON ACCOUNT.

What I didn't realize was that they eventually added support for animated GIFs.
 
they eventually added support for animated GIFs.
I think it always was done by the OS layer. I think I already used GIFs in VFP7. I could misremember that - I might have only used the transparency feature in an unanimated GIF, but I also remember I used BMP with a MSK mask file, that was better in some aspect., but clearly not about animation, which only GIF would support as image, otherwise there are even examples with simple AVIs, like the SEARCH.AVI you also still find in HOME()+"GRAPHICS\VIDEOS\SEARCH.AVI".

There was some kind of switch with VFP9 to also support PNG and gdiplus.dll became part of the runtime libraries you had to release with a VFP application. I remember that was causing some effects on reports, generally printing a few % wider and causing ***** in numeric report controls that were precisely dimensioned in previous versions. If I'm wrong about GIF animation support in VFP7 the animation support simply was a sideeffect of delegating graphics to GDI+. The switch to GDI+ surely allowed support of more GIFs, but I think there are also GIF files that won't work with GDI+, just like some PNGs with alpha channel still don't work with VFP9. GDI+ is good, even quite excellent in resizing images with high quality of edge shaprness, for example, but it's not the definitive image library.
 
Last edited:
Hi all
Attached some sample gifs that I tried. Am using visual foxpro 9200.gif
 

Attachments

  • giphy.gif
    giphy.gif
    1.3 MB · Views: 2
Those GIFs work fine for me.
What's your exact version displayed by VERSION(4)?

With SP2 and hotfixes you get to 09.00.0000.7423 and there those GIFs work fine as pictures of an image control (and what else is there to use them, except going more low level with GdiPlusX.app?). The GIFs even work using using isometric stretching of the image control to adapt the size.

Are you perhaps using legacy FoxPro code @say .. BITMAP to display these GIFs? I guess the legacy commands are kept as is for downward compatibility and won't supoprt GIF animations.
 
Last edited:
Hi chris

I now created a small test form, put an image control on it and ran the form. It's working. Can't figure out why when i did the exact same thing earlier it did not work

Yes I have updated VFP to SP2 and version 09.00.0000.7423 is what I use for development

Thanks again
Ravi
 
Hi all

Just an observation .. I have created a form to display large set of records (53350) from a mysql table in a grid.

I have an image control with a gif which is supposed to be showing the animations while my mySql query is running. the problem is .. the gif animates fine in the image control but moment the query starts executing, (for about 4 5 seconds) the animation stops/freezes and resumes after the query is over

this about defeats the purpose of the animated gif. Has anyone any observations/advice on this?

thanks
Ravi
 
Thanks for the heads up on this.

As I said earlier the OS should care about the animation, once the GIF is set up as picture property, at least there's nothing to code on the VFP side. So it seems the OS does not have an own GDI+ related process or thread that does the automation time scheduled or whatever and maybe that's also too much asked. It shows the process is involved somehow, even if it delegates the taks to the gdiplius.dll. If the process is busy, the animation stops.

So one simple solution would be outsourcing the GIF animation into a separate Progress.exe which you start to show a GIF undefinitely. You just will need a mechanism to finally stop it, which could be done with WMI and terminating a process or using SendMessage and Listen for a specific message to stop. It shouldn't be hard to make a project that only has a top level form showing an animated GIF and then stays forever in READ EVENTS.

Before going into programming the killprocess or listening (Bindevents) to a stop message, let's see if that keeps the animation going, while your main process gets busiy with a query. It's a bit awkward, as the query is done by yet another process, maybe even remotely, within a MySQL Server. But I guess what keeps VFP busy enough is receiving the query result, especially such a large result set. So one other solution would be limiting the result and establish paging data, look up LIMIT in the MySQL/MariaDB documentation to solve it that way.

I know, that fails to handle any situation of a busy process to still show an indefinitely running animation as a sign of progress to the user, and also as a sign of still being alive and well. So that problem should still be solved. On the other hand outsourcing it could lead to a situation the animation runs as a sign of your application to be well, while it could actually get into an unresponsive or even stuck state. Less likely with a query that still has a finite nature, but with anything else you might use this in future cases, of yet unknown nature. So ideally you have something that is kept within the main process and thereby definitely gives a hint about the processes own health state. Since you have no real multithreading and as far as I know Calvin Hsia's multithreading trick does not work without downsides (you have to lower the security by allowing data execution and thus eliminitate the security data excution prevention the OS usually ensures), but the only other option of a timer will suffer from a busy process, too. So from that perspective I see no other choice as to put the feedback of a busy process into a secondary process.

Edit: I forgot on option: Using COM autmation, building an OlePublic class in an out-of-process COM Server EXE.
 
Last edited:
Using COM autmation, building an OlePublic class in an out-of-process COM Server EXE.
To show an example:
1. create a new project you call "progress"
2. create a main.prg as main program of the project with this code:
Code:
Define Class GIF as Form Olepublic
   Add Object Image1 as Image
   Caption = ""
   BorderStyle = 0
   ShowWindow = 2
   ShowInTaskBar = .F.
   GIF = ""
 
   Procedure GIF_assign()
       Lparameters tcGIF
       This.GIF = tcGIF
 
       With Thisform
          .Visible = .F.
          .AutoCenter = .F.
          .Image1.Picture = tcGIF
          .Width = .Image1.Width
          .Height = .Image1.Height
          .AlwaysOnTop = .T.
          .AutoCenter = .T.
          .Visible = .T.
          .TitleBar = 0
          .Show()
       EndWith
   EndProc
Enddefine
3. Build an EXE from that

4. Use it with:
Code:
oGIF = CreateObject("Progress.GIF")
oGIF.GIF = ... image file name...

* do something, i.e. a MySQL query

* when done, quit by killing it:
oGIF = .null.

Testing with morphfox.gif I see a grey bar to the right. I think that's due to minimum width of top level forms (i.e. a Windows restriction?). It's not a problem with your sample GIF images, though. Just have large enough GIF images.

One more usage possibility: If you set GIF to another image, the other GIF shows, so you can switch animations, while this COM server runs.
And I tested it running while the main process simply does DO WHILE .T. ENDDO without a DOEVENTS, in comparison with a GIF attached to the _screen of the same main process. The GIF internal to the main process also still animates, just a little slower than the secondary process oGIF form, but still smoothly, so in my experience you wouldn't need this, I also can't think of anything that keeps a VFP process more busy than that endless WHILE loop, but who knows. I'm just not going into creating as much dummy data or a complex query to test your exact scenario.

For usage within an application: The setup has to include progress.exe built from this code and register the Progress.GIF COM server OLE class.

You can, of course, name the project as you like, that effects the OLE class name. Naming it progress.pjx->progress.exe allows to add further classes in the future, that show a progressbar, for example, or other ways of showing progress, you already have the roof EXE for all that.
 
Last edited:

Part and Inventory Search

Sponsor

Back
Top