Hello.
How can i put an animated GIF to my dialog in my native Win32 application?
I have a loading indicator, and a loading process.
Thanks :-)
Hello.
How can i put an animated GIF to my dialog in my native Win32 application?
I have a loading indicator, and a loading process.
Thanks :-)
Maybe some third party component can do this, but native win32 won't. Heck, it wouldn't even BLT a GIF to a DC last time I looked (though StretchDIBits will handle PNG). Failing that, you'll have to find a library that can crack open an animated GIF and use it to convert the frames to an array of HBITMAPs and BLT them to the window under the control of a timer.
EDIT: As pointed out in the comments GDI+ will handle animated GIF.
You could use the Animation Control. You would have to convert your .gif to an .avi though.
Since you have a tight timeframe on this one I searched for a working example to animate gifs on win32 and I found a nice implementation on cplusplus.com.
It's called GIF View [direct link] by Juan Soulie.
Not sure if GDI+ could be considered as native win32. In case you can use it check the following example: CodeProject
It's fairly simple to implement a timer to change what's displayed. You might set up a text block, with no text in it, with a background color and just change the size. It will look like an expanding colored bar with very little overhead.
Its very easy to use GdiPlus to load a variety of image formats including jpeg, gif (animated), png and so on.
This code demonstrates how to quickly load a single frame of an image into an HBITMAP :-
#include <gdiplus.h>
#pragma comment(lib,"gdiplus.lib")
using namespace Gdiplus;
HBITMAP LoadImageWithGdiPlus(LPCTSTR pszPngPath)
{
Image image(pszPngPath);
int width = image.GetWidth();
int height = image.GetHeight();
BITMAPINFO bmi;
bmi.bmiHeader.biBitCount = 32;
bmi.bmiHeader.biClrImportant = 0;
bmi.bmiHeader.biClrUsed = 0;
bmi.bmiHeader.biCompression = BI_RGB;
bmi.bmiHeader.biHeight = height;
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biSize = sizeof (bmi.bmiHeader);
bmi.bmiHeader.biSizeImage = 0; //calc later
bmi.bmiHeader.biWidth = width;
bmi.bmiHeader.biXPelsPerMeter = 0;
bmi.bmiHeader.biYPelsPerMeter = 0;
BYTE* pBmp = NULL;
HBITMAP hbm = CreateDIBSection(NULL,&bmi,DIB_RGB_COLORS,(void**)&pBmp,NULL,0);
HDC hdc = CreateCompatibleDC(NULL);
HGDIOBJ hobj = SelectObject(hdc,hbm);
Graphics graphics(hdc);
graphics.DrawImage(&image,0,0);
SelectObject(hdc,hobj);
DeleteDC(hdc);
return hbm;
}