简体   繁体   中英

Animated Image in Win32

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

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

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

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

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM