Jump to content
Sign in to follow this  
buymeapc

How Can I Animate A Set Of BMPs Like A GIF?

Recommended Posts

buymeapc

What I'd like to do is rather simple, or so I thought, but I'm having a tough time relaying my thoughts into code. I'd like to have an animated image from a set of bmp's in the status bar area much like a progress bar. When a task is started, animate it and stop when the task is finished.

I tried using the progress bar in the status bar and it worked well until my app went into fullscreen. I was using the "_ProgressSetMarquee" function that works beautifully, but not for my purposes.

What I have doesn't work at all, but it will at least (kind of) show what I'm trying to do...I hope.

#include <GUIConstantsEx.au3>
#include <GuiImageList.au3>
#include <GuiStatusBar.au3>
#include <ButtonConstants.au3>
#Include <GuiButton.au3>
Global $doggyOn = False
Dim $aParts[3] = [75, 100, -1]
Dim $folder = @DesktopDir&"\Dog"
AdlibRegister("StartDoggy", 100)
$hImage =  _GUIImageList_Create(16, 16, 5, 3)
   _GUIImageList_AddBitmap($hImage, $folder&"\DOG1.bmp")
   _GUIImageList_AddBitmap($hImage, $folder&"\DOG2.bmp")
   _GUIImageList_AddBitmap($hImage, $folder&"\DOG3.bmp")
   _GUIImageList_AddBitmap($hImage, $folder&"\DOG4.bmp")
   _GUIImageList_AddBitmap($hImage, $folder&"\DOG5.bmp")
   _GUIImageList_AddBitmap($hImage, $folder&"\DOG6.bmp")
   _GUIImageList_AddBitmap($hImage, $folder&"\DOG7.bmp")
$hGUI =  GUICreate("", 400, 100)
$hStatus =  _GUICtrlStatusBar_Create($hGUI)
   _GUICtrlStatusBar_SetParts($hStatus, $aParts)
$pic =  GUICtrlCreateButton("", 0, 0, -1, -1, BitOR($BS_FLAT, $BS_BITMAP))
   GUICtrlSetState(-1, $GUI_DISABLE)
   _GUICtrlButton_SetImageList($pic, $hImage)
   _GUICtrlStatusBar_EmbedControl($hStatus, 1, GUICtrlGetHandle($pic))
 
GUISetState()
While 1
$msg = GUIGetMsg()
Select
  Case $msg = $GUI_EVENT_CLOSE
   ExitLoop
  Case $msg = $pic
   $doggyOn = False
EndSelect
WEnd
Func StartDoggy()
If $doggyOn = False Then
  $doggyOn = True
  For $x = 1 To 6
   _GUICtrlButton_SetImage($pic, $hImage, $x)
   Sleep(100)
  Next
ElseIf $doggyOn = True Then
  _GUICtrlButton_SetImage($pic, $hImage, 0)
EndIf
EndFunc

Thanks for the help!

Share this post


Link to post
Share on other sites
monoscout999

The pic isnt created when you register "StartDoggy" function, try to create all the controls and the variables that you use in the function before registering the adlib funcion,

Edited by monoscout999

Share this post


Link to post
Share on other sites
buymeapc

Ok, thanks for the reply.

I added the $pic variable to the global variables. It still won't cycle through the images though. I originally had the GUICtrlCreateButton as a GUICtrlCreatePic, but I couldn't get that to work with the image list. What else could I be missing?

Thanks!

Share this post


Link to post
Share on other sites
buymeapc

Ok, I've kind of got it working, but I don't know how to keep the images cycling while keeping the ability to work with the GUI. With the way I have it below, the process gets stuck in the For loop and I can't do anything with the GUI. How can I accomplish this?

Thanks!!

#include <GUIConstantsEx.au3>
#include <GuiImageList.au3>
#include <GuiStatusBar.au3>
#include <ButtonConstants.au3>
#Include <GuiButton.au3>
Global $pic, $doggyOn = False
Global $folder = @DesktopDir&"\Dog"
Global $hImage[7] = [$folder&"\DOG1.bmp", $folder&"\DOG2.bmp", $folder&"\DOG3.bmp", $folder&"\DOG4.bmp", $folder&"\DOG5.bmp", $folder&"\DOG6.bmp", $folder&"\DOG7.bmp"]
Dim $aParts[3] = [75, 100, -1]
AdlibRegister("StartDoggy", 100)
 
$hGUI =  GUICreate("", 400, 100)
$button = GUICtrlCreateButton("Start Dog", 10, 10)
$hStatus =  _GUICtrlStatusBar_Create($hGUI)
   _GUICtrlStatusBar_SetParts($hStatus, $aParts)
$pic =  GUICtrlCreatePic($hImage[0], 0, 0)
   GUICtrlSetState(-1, $GUI_DISABLE)
   _GUICtrlStatusBar_EmbedControl($hStatus, 1, GUICtrlGetHandle($pic))
 
GUISetState()
While 1
$msg = GUIGetMsg()
Select
  Case $msg = $GUI_EVENT_CLOSE
   ExitLoop
  Case $msg = $button
   $doggyOn = False
EndSelect
WEnd
Func StartDoggy()
If $doggyOn = False Then
  $doggyOn = True
  For $x = 0 To 6
   GUICtrlSetImage($pic, $hImage[$x])
   Sleep(100)
   If $x = 6 Then $x = 0
  Next
ElseIf $doggyOn = True Then
  GUICtrlSetImage($pic, $hImage[0])
EndIf
EndFunc

Share this post


Link to post
Share on other sites
UEZ

Try this:

#include <ScreenCapture.au3>
_GDIPlus_Startup()
Global Const $w = 100
Global Const $h = 100
Global Const $frames = 200
Global $hImages[$frames]
Global $i, $hHBitmap

For $i = 0 To $frames - 1
    $hHBitmap = _ScreenCapture_Capture("", $i, 0, $i + $w, $h, False)
    $hImages[$i] = _GDIPlus_BitmapCreateFromHBITMAP($hHBitmap)
    _WinAPI_DeleteObject($hHBitmap)
Next

Global Const $hGUI = GUICreate("Test", $w, $h)
GUISetState(@SW_SHOW)

Global Const $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGui)

AdlibRegister("Display_Frames", 50)

While GUIGetMsg() <> -3
WEnd

AdlibUnRegister("Display_Frames")

For $i = 0 To $frames - 1
    _GDIPlus_BitmapDispose($hImages[$i])
Next
 _GDIPlus_GraphicsDispose($hGraphics)
_GDIPlus_Shutdown()
GUIDelete($hGUI)
Exit

Func Display_Frames()
    Local Static $j = 0
    _GDIPlus_GraphicsDrawImage($hGraphics, $hImages[Mod($j, $frames)], 0, 0)
    $j += 1
EndFunc

It will take 200 snapshots and will display the frames in the GUI which looks like an animation.

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
monoscout999

nice script UEZ i never saw a Static variable they seems very usefull today i learn something new.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×