views:

124

answers:

6

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 :-)

A: 

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.

Marcelo Cantos
Thank you. I have very limited time ahead of me so i'm trying to figure this out quickly. I'm trying to use a progress bar control with the marquee style applied but, no luck.
frbry
This answer wins? You got to be kidding.GDI+ will crack open the GIF frames and can provide the frame timing information. Create a timer (ala SetTimer) to notify you when it's time to update the frame.
selbie
Hmm, I always thought GDI+ was .Net based (just found out it isn't).
Marcelo Cantos
+4  A: 

You could use the Animation Control. You would have to convert your .gif to an .avi though.

Fozi
The follow-up question is "How do you convert a .gif to a .avi?" Include that in your answer and it would be perfect.
Mark Ransom
Since Imagemagick failed, all I can offer is what google brought up. (which is not too bad - I searched for `convert gif to avi`) Maybe someone else has a good idea?
Fozi
A: 

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.

mre
+2  A: 

Not sure if GDI+ could be considered as native win32. In case you can use it check the following example: CodeProject

Voivoid
A: 

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.

Jay
A: 

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;
}
Chris Becke