January 26, 2023, 09:48:52 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Yet another way to load animated gif

Started by sapero, August 19, 2009, 04:46:14 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

sapero

This example uses IShellImageData shell interface to load animated image. This interface is available on Windows XP.

#include "ShImgData.inc"
#use "urlmon.lib"

sub main()
{
CoInitialize(0);

dwstring wszPath[MAX_PATH]; // download a .gif to cache
if (!URLDownloadToCacheFileW(0, L"http://www.thegraphicgroove.com/oddBits/Butterfly2.gif", wszPath, MAX_PATH, 0, 0))
{
IShellImageDataFactory *factory;
if (!CoCreateInstance(_CLSID_ShellImageDataFactory, NULL, CLSCTX_INPROC_SERVER, _IID_IShellImageDataFactory, &factory))
{
IShellImageData *data;
if (!factory->CreateImageFromFile(wszPath, &data))
{
data->Decode(SHIMGDEC_DEFAULT,0,0);

RECT rc;
rc.left = 0;
rc.top = 0;
data->GetSize(&rc.right);
HDC dc = GetDC(0);
data->Draw(dc, &rc, &rc);

if (!data->IsAnimated())
{
while (!(GetAsyncKeyState(VK_ESCAPE)&0x8000))
{
int time;
TextOut(dc,4,rc.bottom,"Press ESC to quit",17);
data->GetDelay(&time);
Sleep(time);
if (data->NextFrame()) data->SelectPage(0);
data->Draw(dc, &rc, &rc);
}
}
else
{
Sleep(2000);
}
ReleaseDC(0, dc);
// remove image from desktop
rc.bottom += 20;
InvalidateRect(0, &rc, TRUE);
data->Release();
}
factory->Release();
}
}
CoUninitialize();
}

Instead sleeping, you can put it in a timer.