Jump to content

How to create animated GIF pics?


AlmarM
 Share

Recommended Posts

Hi,

this time I would like to know how to make 'Animated' GIF pics in my GUI. Anyone know this?

Did I miss something in the helpfile :P?

Please let me know :(

AlmarM

Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Link to comment
Share on other sites

Hmmm, I dont realy get it :P

#AutoIt3Wrapper_useupx=n
#AutoIt3Wrapper_run_after=ResHacker.exe -add %out%, %out%, gif-Green-UFO.gif, rcdata, TEST_GIF_1, 0
#AutoIt3Wrapper_run_after=upx.exe --best --compress-resources=0 "%out%"

#include "resources.au3"

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
#include <Misc.au3>
#include <WinAPI.au3>
#include <Timers.au3>

HotKeySet("{Esc}", "Quit")
HotKeySet("{Left}", "Left")
HotKeySet("{Right}", "Right")
HotKeySet("{Pause}", "Pause")

;~ Global $Gif = @ScriptDir & "\gif-Green-UFO.gif"
Global $i = 0, $ApX, $ApY, $ApW, $ApH, $eX, $eY
Global $hImage, $hBitmap, $hScrDC, $hMemDC, $tSize, $pSize, $tSource, $pSource, $tBlend, $pBlend
Global $GFC, $GFDC, $pDimensionIDs, $tDL
Global $Pause

Global $MadeLoops, $LoopCount
Global $FrameDelays
Global $GIF_TimerID = -1

Global Const $tagPropertyItem = "long id; long length; int Type; ptr value"
Global Const $PropertyTagFrameDelay = 0x5100
Global Const $PropertyTagLoopCount = 0x5101

Global Const $PropertyTagTypeByte = 1
Global Const $PropertyTagTypeASCII = 2
Global Const $PropertyTagTypeShort = 3
Global Const $PropertyTagTypeLong = 4
Global Const $PropertyTagTypeRational = 5
Global Const $PropertyTagTypeUndefined = 7
Global Const $PropertyTagTypeSLong = 9
Global Const $PropertyTagTypeSRational = 10

;~ $hGUI = GUICreate("", 0, 0, 0, 0, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOOLWINDOW, $WS_EX_TOPMOST))
$hGUI = GUICreate("GIF Animation",300,300)
GUICtrlCreateLabel("text behind GIF",5,15,100,25)
Global $IMG_Ctrl= GUICtrlCreateLabel("",10,10,10,10) ; For Drawing 
GUICtrlSetBkColor(-1,$GUI_BKCOLOR_TRANSPARENT) ; Transparency's working 

GUISetState()

GifInit()

; move the window with animated GIF image
;~ AdlibEnable("FlyUfo", 20)
$GIF_TimerID = _Timer_SetTimer($hGUI, 100, "_Draw_Timer") ; Start Animation
While 1
    If GUIGetMsg() = -3 Then Quit()
WEnd

Func _Draw_Timer($hWnd, $Msg, $iIDTimer, $dwTime)
    If $LoopCount = 0 Or ($LoopCount > $MadeLoops) Then
        ; If $i = the frame count then reset $i to 0
        If $GIF_TimerID = 0 Then $GIF_TimerID = -1
        If $i = $GFC Then $i = 0
        If UBound($FrameDelays) > $i And $FrameDelays[$i] > 0 Then
            _Timer_SetTimer($hWnd, $FrameDelays[$i], "_Draw_Timer", $iIDTimer)
        Else
            _Timer_SetTimer($hWnd, 100, "_Draw_Timer", $iIDTimer)
            ConsoleWrite("Fallback, no time found " & @CRLF)
        EndIf
;~   GifDrawFrame($i)
        GifDrawFrame_Ctrl($i)
        $i += 1
    Else
        _Timer_KillTimer($hWnd, $iIDTimer)
    EndIf
EndFunc   ;==>_Draw_Timer
Func Quit()
    _Timer_KillAllTimers($hGUI)
    ;Tidy Up at end of each frame, otherwise memory use gets excessive in a short time.
    _GDIPlus_ImageDispose($hImage)

    _GDIPlus_Shutdown()

    HotKeySet("{Esc}")
    HotKeySet("{Left}")
    HotKeySet("{Right}")
    HotKeySet("{Pause}")

    Exit
EndFunc   ;==>Quit

Func GifInit()
    _GDIPlus_Startup()
    ; Load your animated gif
;~     $hImage = _GDIPlus_ImageLoadFromFile($Gif)
;~     If @error Then _WinAPI_FatalAppExit("Image " & $Gif & " not found!" & _GDIPlus_Shutdown())
    $hImage = _ResourceGetAsImage("TEST_GIF_1")
    If @error Then _WinAPI_FatalAppExit("Image resource TEST_GIF_1 not found!" & _GDIPlus_Shutdown())
 
    $ApW = _GDIPlus_ImageGetWidth($hImage)
    $ApH = _GDIPlus_ImageGetHeight($hImage)

    GUICtrlSetPos($IMG_Ctrl,Default,Default,$ApW,$ApH) ;Set Size of the Control 

    ; Create a struct to hold the GUID.
    $tDL = DllStructCreate($tagGUID)

    ; Get a pointer to the GUID struct.
    $pDimensionIDs = DllStructGetPtr($tDL)

    ; Get the FrameDimensionsCount of the loaded gif
    $GFDC = DllCall($ghGDIPDll, "int", "GdipImageGetFrameDimensionsCount", "ptr", $hImage, "int*", 0)

    ; Get the FrameDimensionsList , which fills the GUID struct by passing the GUID pointer and the FrameDimensionsCount.
    DllCall($ghGDIPDll, "int", "GdipImageGetFrameDimensionsList", "ptr", $hImage, "ptr", $pDimensionIDs, "int", $GFDC[2])

    ; Get the FrameCount of the loaded gif by passing the GUID pointer
    $GFC = DllCall($ghGDIPDll, "int", "GdipImageGetFrameCount", "int", $hImage, "ptr", $pDimensionIDs, "int*", 0)
    $GFC = $GFC[3]
    $FrameDelays = _GetFrameDelays($hImage, $GFC)
    $LoopCount = _GetGifLoopCount($hImage)
EndFunc   ;==>GifInit

Func GifDrawFrame_Ctrl($i)
    ; Select the ActiveFrame in the loaded gif by telling it. The frame starts @ 0 ($i)
    DllCall($ghGDIPDll, "int", "GdipImageSelectActiveFrame", "ptr", $hImage, "ptr", $pDimensionIDs, "int", $i)

    ; The rest is just a copy and paste on updating a layered window with the loaded gif.
    ; I tried using _GDIPlus_GraphicsDrawImage() but no matter what I did memory was getting chewed up. leak maybe?
    ; But using the Update layered window and memory use seems to level out and sit pretty idle
    $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
    _SetBitmapToCtrl($IMG_Ctrl,$hBitmap)
    _WinAPI_DeleteObject($hBitmap)
EndFunc   ;==>GifDrawFrame

; internal helper function, out of reources UDf from Zedna
;~ Func _SetBitmapToCtrl($CtrlId, $hBitmap)
;~     Local Const $STM_SETIMAGE = 0x0172
;~     Local Const $IMAGE_BITMAP = 0
;~     Local Const $SS_BITMAP = 0xE
;~     Local Const $GWL_STYLE = -16
;~     Local Const $SS_REALSIZEIMAGE = 0x800

;~     Local $hWnd = GUICtrlGetHandle($CtrlId)
;~     If $hWnd = 0 Then Return SetError(1, 0, 0)
;~         ; set SS_BITMAP style to control
;~     Local $oldStyle = DllCall("user32.dll", "long", "GetWindowLong", "hwnd", $hWnd, "int", $GWL_STYLE)
;~     If @error Then Return SetError(2, 0, 0)
;~     DllCall("user32.dll", "long", "SetWindowLong", "hwnd", $hWnd, "int", $GWL_STYLE, "long", BitOR($oldStyle[0], $SS_BITMAP,$SS_REALSIZEIMAGE))
;~     If @error Then Return SetError(3, 0, 0)
;~         Local $oldBmp = DllCall("user32.dll", "hwnd", "SendMessage", "hwnd", $hWnd, "int", $STM_SETIMAGE, "int", $IMAGE_BITMAP, "int", $hBitmap)
;~     If @error Then Return SetError(4, 0, 0)
;~     If $oldBmp[0] <> 0 Then _WinAPI_DeleteObject($oldBmp[0])
;~     Return 1
;~ EndFunc

; move the window with animated GIF image
Func FlyUfo()
    Local $Speed = 0
    Do
        If $ApX >= (@DesktopWidth - $ApW) Then
            $eX = "$ApX - 1"
        ElseIf $ApX <= 0 Then
            $eX = "$ApX + 1"
        EndIf
        If $ApY >= (@DesktopHeight - $ApH) Then
            $eY = "$ApY - 1"
        ElseIf $ApY <= 0 Then
            $eY = "$ApY + 1"
        EndIf
        $ApX = Execute($eX)
        $ApY = Execute($eY)
        WinMove($hGUI, "", $ApX, $ApY)
        $Speed += 1
    Until $Speed = 5
EndFunc   ;==>FlyUfo

Func Left()
    If WinActive($hGUI) Then
        If Not $Pause Then Return
        $i -= 1
        If $i = -1 Then $i = $GFC - 1
;~   GifDrawFrame($i)
        GifDrawFrame_Ctrl($i)
    Else
        HotKeySet("{Left}")
        Send("{Left}")
        HotKeySet("{Left}", "Left")
    EndIf
EndFunc   ;==>Left

Func Right()
    If WinActive($hGUI) Then
        If Not $Pause Then Return
        $i += 1
        If $i = $GFC Then $i = 0
;~   GifDrawFrame($i)
        GifDrawFrame_Ctrl($i)
    Else
        HotKeySet("{Right}")
        Send("{Right}")
        HotKeySet("{Right}", "Right")
    EndIf
EndFunc   ;==>Right

Func Pause()
    If WinActive($hGUI) Then
        $Pause = Not $Pause
        if $Pause Then
            _Timer_KillTimer($hGUI,$GIF_TimerID)
        Else
            $GIF_TimerID = _Timer_SetTimer($hGUI, 100, "_Draw_Timer") ; Start Animation
        EndIf

    Else
        HotKeySet("{PAUSE}")
        Send("{PAUSE}")
        HotKeySet("{PAUSE}", "Pause")
    EndIf
EndFunc   ;==>Pause

; Author: Prog@ndy (converted from VB  )
; VB-Source: http://www.activevb.de/tipps/vb6tipps/tipp0675.html
Func _GetFrameDelays(ByRef $hImage, $FrameCount)
    
    Local $lOutFrameDelay[$FrameCount]
    

;~  Dim lProp() As Byte
;~  Dim lPropCount As Long
    Local $lSize ;As Long
;~  Dim lPropSize As Long
;~  Dim tPropItem As PropertyItem
    Local $PropID = $PropertyTagFrameDelay
    If Not _CheckForProperty($hImage, $PropID) Then Return SetError(1, 0, 0)
    Local $PropertySize = DllCall($ghGDIPDll, "int", "GdipGetPropertyItemSize", "ptr", $hImage, "dword", $PropID, "uint*", 0)

;~     ' Datengröße vom EXIF-Tag
;~     ' "PropertyTagFrameDelay" ermitteln
    If $PropertySize[0] = 0 Then
        $tPropItem = DllStructCreate($tagPropertyItem & ";byte[" & $PropertySize[3] & "]"); Create Property-ItemStruct and save enough memory for its data
        Local $PropertyItem = DllCall($ghGDIPDll, "int", "GdipGetPropertyItem", "ptr", $hImage, "dword", $PropID, "dword", $PropertySize[3], "ptr", DllStructGetPtr($tPropItem))
        If $PropertyItem[0] <> 0 Then Return SetError(1, 0, 0)
        $lSize = DllStructGetData($tPropItem, "length")
;~    ' PropertyTyp ermitteln
        Switch DllStructGetData($tPropItem, "Type")
            Case $PropertyTagTypeByte
                $lProp = DllStructCreate("byte[" & $lSize & "]", DllStructGetData($tPropItem, "value"))
;~      $lSize = "byte"
                ConsoleWrite("byte" & @CRLF)
            Case $PropertyTagTypeShort
                $lProp = DllStructCreate("short[" & Ceiling($lSize / 2) & "]", DllStructGetData($tPropItem, "value"))
;~      $lSize = "ushort"
                ConsoleWrite("short" & @CRLF)

            Case $PropertyTagTypeLong
                $lProp = DllStructCreate("long[" & Ceiling($lSize / 4) & "]", DllStructGetData($tPropItem, "value"))
;~      $lSize = "long"
                ConsoleWrite("long" & @CRLF)
        EndSwitch

;~      ' Pausenzeiten der einzelnen
;~      ' Bilder aus Bytearray kopieren
        For $lPropCount = 0 To $FrameCount - 1
            $lOutFrameDelay[$lPropCount] = DllStructGetData($lProp, 1, $lPropCount + 1) * 10


        Next
    EndIf
;~  _MemGlobalFree(DllStructGetData($tPropItem,"value"))
;~  _MemVirtualFree(DllStructGetData($tPropItem,"value"),$lSize,$MEM_RELEASE)
    Return $lOutFrameDelay
EndFunc   ;==>_GetFrameDelays

; Author: Prog@ndy (converted from VB  )
; VB-Source: http://www.activevb.de/tipps/vb6tipps/tipp0675.html
;~ '------------------------------------------------------
;~ ' Funktion     : GetGifLoopCount
;~ ' Beschreibung : Auslesen der Wiederholungen
;~ ' Ãœbergabewert : lInBitmap = GDI+ Bitmapobjekt
;~ '                lOutLoopCount = Anzahl der Wiederholungen
;~ '------------------------------------------------------
Func _GetGifLoopCount(ByRef $hImage)

    Local $tPropItem
    Local $lProp
    Local $lSize

;~     ' ist der EXIF-Tag
;~     ' "PropertyTagLoopCount" vorhanden
    If _CheckForProperty($hImage, _
            $PropertyTagLoopCount) = True Then

;~     ' Datengröße vom EXIF-Tag
;~     ' "PropertyTagLoopCount" ermitteln
        Local $PropertySize = DllCall($ghGDIPDll, "int", "GdipGetPropertyItemSize", "ptr", $hImage, "dword", $PropertyTagLoopCount, "uint*", 0)
        If $PropertySize[0] = 0 Then

;~             ' Daten auslesen
            
            $tPropItem = DllStructCreate($tagPropertyItem & ";byte[" & $PropertySize[3] & "]"); Create Property-ItemStruct and save enough memory for its data
            Local $PropertyItem = DllCall($ghGDIPDll, "int", "GdipGetPropertyItem", "ptr", $hImage, "dword", $PropertyTagLoopCount, "dword", $PropertySize[3], "ptr", DllStructGetPtr($tPropItem))
            If $PropertyItem[0] <> 0 Then Return SetError(1, 0, 0)


            $lSize = DllStructGetData($tPropItem, "length")
;~    ' PropertyTyp ermitteln
            Switch DllStructGetData($tPropItem, "Type")
                Case $PropertyTagTypeByte
                    $lProp = DllStructCreate("byte[" & $lSize & "]", DllStructGetData($tPropItem, "value"))
;~      $lSize = "byte"
                    ConsoleWrite("byte" & @CRLF)
                Case $PropertyTagTypeShort
                    $lProp = DllStructCreate("short[" & Ceiling($lSize / 2) & "]", DllStructGetData($tPropItem, "value"))
;~      $lSize = "ushort"
                    ConsoleWrite("short" & @CRLF)

                Case $PropertyTagTypeLong
                    $lProp = DllStructCreate("long[" & Ceiling($lSize / 4) & "]", DllStructGetData($tPropItem, "value"))
;~      $lSize = "long"
                    ConsoleWrite("long" & @CRLF)
            EndSwitch
            Return DllStructGetData($lProp, 1, 1)

        EndIf

    Else
;~   ' wenn der EXIF-Tag
;~   ' "PropertyTagLoopCount" fehlt
        Return 0
    EndIf
EndFunc   ;==>_GetGifLoopCount


; Author: Prog@ndy (converted from VB  )
; VB-Source: http://www.activevb.de/tipps/vb6tipps/tipp0675.html
;~ '------------------------------------------------------
;~ ' Funktion     : CheckLoopCount
;~ ' Beschreibung : Überprüft, ob der EXIF-Tag LoopCount
;~ '                vorhanden sind
;~ ' Ãœbergabewert : lInBitmap = GDI+ Bitmapobjekt
;~ ' Rückgabewert : True = LoopCount vorhanden
;~ '                False = LoopCount nicht vorhanden
;~ '------------------------------------------------------
Func _CheckForProperty( _
        ByRef $hImage, _
        $PropertyID)

    Local $lPropItem
    Local $lPropList


    Local $bRet = False

;~     ' Anzahl der EXIF-Metatags ermitteln
    Local $PropertyCount = DllCall($ghGDIPDll, "int", "GdipGetPropertyCount", "ptr", $hImage, "long*", 0)
    If $PropertyCount[0] = 0 Then


;~         ' sind EXIF-Metatags vorhanden
        If ($PropertyCount[2] > 0) Then

;~             ' Array zur Aufnahme der
;~             ' EXIF-Metatags dimensionieren
            Local $lPropList = DllStructCreate("dword[" & $PropertyCount[2] & "]")

;~             ' Liste der EXIF-Metatags auslesen -> lPropList()
            Local $PropertyList = DllCall($ghGDIPDll, "int", "GdipGetPropertyIdList", "ptr", $hImage, "long", $PropertyCount[2], "ptr", DllStructGetPtr($lPropList))
            If $PropertyList[0] = 0 Then

;~     ' Liste der EXIF-Metatags durchlaufen
                For $lPropItem = 1 To $PropertyCount[2]

;~                     ' ist in der Liste der EXIF-Metatag
;~                     ' PropertyID vorhanden

                    If DllStructGetData($lPropList, $lPropItem) = $PropertyID Then

;~                         ' wenn ja, dann Rückgabewert setzen und
;~                         ' Schleife verlassen
                        $bRet = True
                        ExitLoop
                    EndIf

                Next

            EndIf
        EndIf
    EndIf

;~     ' Rückgabewert ausgeben
    Return $bRet
EndFunc   ;==>_CheckForProperty

So what do I actualy use to make an Animated GIF?

Its a specific func? Or a whole code?

AlmarM

Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Link to comment
Share on other sites

  • 1 year later...

hi guys, does anyone knows how to display the animated gif (famous example is of coz green-UFO.gif) without the GUI/windows?

I still do not found any example of animated gif without the windows frame...for now, it's only applicable for png

AUTOIT[sup] I'm lovin' it![/sup]

Link to comment
Share on other sites

hi guys, does anyone knows how to display the animated gif (famous example is of coz green-UFO.gif) without the GUI/windows?

I still do not found any example of animated gif without the windows frame...for now, it's only applicable for png

Hi,

The original animated gif example I posted was:

(Currently works with autoit v3.3.2.0, adlib function changed in autoit since I first wrote it)

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
#include <Misc.au3>
#include <WinAPI.au3>

Global $Gif = @ScriptDir & "\gif-Green-UFO.gif"
Global $i = 0, $ApX, $ApY, $ApW, $ApH, $eX, $eY

_GDIPlus_Startup()

; Load your animated gif
$hImage = _GDIPlus_ImageLoadFromFile($Gif)
$ApW = _GDIPlus_ImageGetWidth($hImage)
$ApH = _GDIPlus_ImageGetHeight($hImage)


$hGUI = GUICreate("", $ApW, $ApH, 0, 0, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOOLWINDOW, $WS_EX_TOPMOST))
GUISetState()

AdlibRegister("FlyUfo", 20)

Do
    ; Create a struct to hold the GUID.
    $tDL = DllStructCreate($tagGUID)

    ; Get a pointer to the GUID struct.
    $pDimensionIDs = DllStructGetPtr($tDL)

    ; Get the FrameDimensionsCount of the loaded gif
    $GFDC = DllCall($ghGDIPDll, "int", "GdipImageGetFrameDimensionsCount", "ptr", $hImage, "int*", 0)

    ; Get the FrameDimensionsList , which fills the GUID struct by passing the GUID pointer and the FrameDimensionsCount.
    DllCall($ghGDIPDll, "int", "GdipImageGetFrameDimensionsList", "ptr", $hImage, "ptr", $pDimensionIDs, "int", $GFDC[2])

    ; Get the FrameCount of the loaded gif by passing the GUID pointer
    $GFC = DllCall($ghGDIPDll, "int", "GdipImageGetFrameCount", "int", $hImage, "ptr", $pDimensionIDs, "int*", 0)

    ; If $i = the frame count then reset $i to 0
    If $i = $GFC[3] Then $i = 0
;~     ConsoleWrite($GFC[3] & @LF)
    ; Select the ActiveFrame in the loaded gif by telling it. The frame starts @ 0 ($i)
    DllCall($ghGDIPDll, "int", "GdipImageSelectActiveFrame", "ptr", $hImage, "ptr", $pDimensionIDs, "int", $i)

    ; At this point you can get the CLSID of an encoder and save the frame to file if you want..
    ; Use any Encoder you like. eg: "GIF", "TIF", "BMP", "JPG"
    ; Transparency won't be saved. (You'd need to play with pallets to have the transparency saved)
;~  $sCLSID = _GDIPlus_EncodersGetCLSID ("PNG")
;~  _GDIPlus_ImageSaveToFileEx ($hImage, @MyDocumentsDir & "\Gif_Frame_" & $i & ".png", $sCLSID)


    ; The rest is just a copy and paste on updating a layered window with the loaded gif.
    ; I tried using _GDIPlus_GraphicsDrawImage() but no matter what I did memory was getting chewed up. leak maybe?
    ; But using the Update layered window and memory use seems to level out and sit pretty idle ;)
    $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
    $hScrDC = _WinAPI_GetDC($hGUI)
    $hMemDC = _WinAPI_CreateCompatibleDC($hScrDC)
    $hOld = _WinAPI_SelectObject($hMemDC, $hBitmap)

    $tSize = DllStructCreate($tagSIZE)
    DllStructSetData($tSize, "X", $ApW)
    DllStructSetData($tSize, "Y", $ApH)
    $pSize = DllStructGetPtr($tSize)

    $tSource = DllStructCreate($tagPOINT)
    $pSource = DllStructGetPtr($tSource)

    $tBlend = DllStructCreate($tagBLENDFUNCTION)
    DllStructSetData($tBlend, "Alpha", 255)
    DllStructSetData($tBlend, "Format", 1)
    $pBlend = DllStructGetPtr($tBlend)

    _WinAPI_UpdateLayeredWindow($hGUI, $hScrDC, 0, $pSize, $hMemDC, $pSource, 0, $pBlend, $ULW_ALPHA)

    ;Tidy Up at end of each frame, otherwise memory use gets excessive in a short time.
;~  _GDIPlus_ImageDispose($hImage)
    _WinAPI_ReleaseDC(0, $hScrDC)
    _WinAPI_DeleteObject($hBitmap)
    _WinAPI_DeleteDC($hMemDC)

    ; By rights I should be using the const PropertyTagFrameDelay and geting the properties time delay between frames.
    ; I cheated , so shoot me...lol
    Sleep(100)

    $i += 1
Until _IsPressed("1B") ;Esc to exit

_GDIPlus_ImageDispose($hImage)
_GDIPlus_Shutdown()

AdlibUnRegister("FlyUfo")

Func FlyUfo()
    Local $Speed = 0
    Do
        If $ApX >= (@DesktopWidth - $ApW) Then
            $eX = "$ApX - 1"
        ElseIf $ApX <= 0 Then
            $eX = "$ApX + 1"
        EndIf
        If $ApY >= (@DesktopHeight - $ApH) Then
            $eY = "$ApY - 1"
        ElseIf $ApY <= 0 Then
            $eY = "$ApY + 1"
        EndIf
        $ApX = Execute($eX)
        $ApY = Execute($eY)
        WinMove($hGUI, "", $ApX, $ApY)
        $Speed += 1
    Until $Speed = 5
EndFunc   ;==>FlyUfo

gif-Green-UFO.gif attached...

post-13029-12615518526779_thumb.gif

Edited by smashly
Link to comment
Share on other sites

And you can always do something like this:

#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include "GIFAnimation.au3"

Opt("GUICloseOnESC", 1); ESC to exit
Opt("MustDeclareVars", 1)

Global $sTempFolder = @TempDir & "\GIFS"
DirCreate($sTempFolder)
Global $sFile = $sTempFolder & "\UFO.gif"
If Not FileExists($sFile) Then
    TrayTip("GIF Download", "Please wait...", 0)
    InetGet("http://www.autoitscript.com/forum/index.php?app=core&module=attach&section=attach&attach_rel_module=post&attach_id=28964", $sFile)
    TrayTip("", "", 0)
EndIf

Global $aGIFDimension = _GIFGetDimension($sFile)

Global $hGui = GUICreate("GIF Animation", $aGIFDimension[0], $aGIFDimension[1], -1, -1, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST))
GUISetBkColor(563)
_WinAPI_SetLayeredWindowAttributes($hGui, 563, 255)

Global $aGIFArrayOfIconHandles
Global $hGIFThread
Global $iGIFTransparent
Global $tFrameCurrent

Global $hGIF = _GUICtrlCreateGIF($sFile, 0, 0, $aGIFArrayOfIconHandles, $hGIFThread, $iGIFTransparent, $tFrameCurrent)

GUISetState()


While 1
    If GUIGetMsg() = - 3 Then Exit
WEnd

GIFAnimation.au3 can be found here <- link

Link to comment
Share on other sites

I have an example script to make the popup image dragable, but this method is not working for animated gif.

You can refer to this video for the intended result, I really love it, you can drag the egg.

Dancing Egg

#include <GuiConstants.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>

Global Const $WM_LBUTTONDOWN = 0x0201

$HWnd = GUICreate("Testing", 256, 256, -1, -1, $WS_POPUP+$WS_BORDER)
GUICtrlCreatePic(@ScriptDir & "\twit.jpg",-1, -1, 256, 256,$SS_SUNKEN)
GUIRegisterMsg($WM_LBUTTONDOWN, "WM_LBUTTONDOWN")
GUISetState()

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func WM_LBUTTONDOWN($hWnd, $iMsg, $wParam, $lParam)
    If BitAND(WinGetState($hWnd), 32) Then Return $GUI_RUNDEFMSG
    DllCall("user32.dll", "long", "SendMessage", "hwnd", $hWnd, "int", $WM_SYSCOMMAND, "int", 0xF009, "int", 0)
EndFunc

post-19602-12617629779302_thumb.jpg

AUTOIT[sup] I'm lovin' it![/sup]

Link to comment
Share on other sites

  • 2 months later...

Hi,

a very nice example! Great!

I want to include this in a own gui - but if i move my gui "Check" the gif stays.

I want the gif stay fixed in my gui ...

What's wrong?

Thx for help!

Dizzy

#include <GUIConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <StaticConstants.au3>
#Include <File.au3>
#include <ButtonConstants.au3>
#include <GDIPlus.au3>
#include <Misc.au3>
#include <WinAPI.au3>

Global $VERSION = "0.10"
Global $Gif = @ScriptDir & "\gif-Green-UFO.gif"

Global $i, $hImage

Opt("WinTitleMatchMode", 2)

HotKeySet("{F10}", "terminate")

;#####################################################################################
;## GUI START                                                                       ##
;#####################################################################################

$Form1 = GUICreate("Check",     650, 425, 150, 150)
$Group1 = GUICtrlCreateGroup("Dir",     20, 4, 610, 125)
$Button1 = GUICtrlCreateButton("Quit ",         20, 385, 80, 25)

GUISetState(@SW_SHOW)
_ani_GIF()

;#####################################################################################
;## GUI START                                                                       ##
;#####################################################################################



While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
        Case $msg = $Button1
            terminate()
        Case Else
    EndSelect
WEnd

exit


Func _ani_GIF()
    _GDIPlus_Startup()

    ; Load your animated gif
    $hImage = _GDIPlus_ImageLoadFromFile($Gif)
    $ApW = _GDIPlus_ImageGetWidth($hImage)
    $ApH = _GDIPlus_ImageGetHeight($hImage)

    $hGUI = GUICreate("", $ApW, $ApH, 600, 390, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOOLWINDOW, $WS_EX_TOPMOST))
    GUISetState()

    Do
        ; Create a struct to hold the GUID.
        $tDL = DllStructCreate($tagGUID)

        ; Get a pointer to the GUID struct.
        $pDimensionIDs = DllStructGetPtr($tDL)

        ; Get the FrameDimensionsCount of the loaded gif
        $GFDC = DllCall($ghGDIPDll, "int", "GdipImageGetFrameDimensionsCount", "ptr", $hImage, "int*", 0)

        ; Get the FrameDimensionsList , which fills the GUID struct by passing the GUID pointer and the FrameDimensionsCount.
        DllCall($ghGDIPDll, "int", "GdipImageGetFrameDimensionsList", "ptr", $hImage, "ptr", $pDimensionIDs, "int", $GFDC[2])

        ; Get the FrameCount of the loaded gif by passing the GUID pointer
        $GFC = DllCall($ghGDIPDll, "int", "GdipImageGetFrameCount", "int", $hImage, "ptr", $pDimensionIDs, "int*", 0)

        ; If $i = the frame count then reset $i to 0
        If $i = $GFC[3] Then $i = 0
    
        ;~     ConsoleWrite($GFC[3] & @LF)
        ; Select the ActiveFrame in the loaded gif by telling it. The frame starts @ 0 ($i)
        DllCall($ghGDIPDll, "int", "GdipImageSelectActiveFrame", "ptr", $hImage, "ptr", $pDimensionIDs, "int", $i)

        ; At this point you can get the CLSID of an encoder and save the frame to file if you want..
        ; Use any Encoder you like. eg: "GIF", "TIF", "BMP", "JPG"
        ; Transparency won't be saved. (You'd need to play with pallets to have the transparency saved)
        ;~  $sCLSID = _GDIPlus_EncodersGetCLSID ("PNG")
        ;~  _GDIPlus_ImageSaveToFileEx ($hImage, @MyDocumentsDir & "\Gif_Frame_" & $i & ".png", $sCLSID)


        ; The rest is just a copy and paste on updating a layered window with the loaded gif.
        ; I tried using _GDIPlus_GraphicsDrawImage() but no matter what I did memory was getting chewed up. leak maybe?
        ; But using the Update layered window and memory use seems to level out and sit pretty idle ;)
        $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
        $hScrDC = _WinAPI_GetDC($hGUI)
        $hMemDC = _WinAPI_CreateCompatibleDC($hScrDC)
        $hOld = _WinAPI_SelectObject($hMemDC, $hBitmap)

        $tSize = DllStructCreate($tagSIZE)
        DllStructSetData($tSize, "X", $ApW)
        DllStructSetData($tSize, "Y", $ApH)
        $pSize = DllStructGetPtr($tSize)

        $tSource = DllStructCreate($tagPOINT)
        $pSource = DllStructGetPtr($tSource)

        $tBlend = DllStructCreate($tagBLENDFUNCTION)
        DllStructSetData($tBlend, "Alpha", 255)
        DllStructSetData($tBlend, "Format", 1)
        $pBlend = DllStructGetPtr($tBlend)

        _WinAPI_UpdateLayeredWindow($hGUI, $hScrDC, 0, $pSize, $hMemDC, $pSource, 0, $pBlend, $ULW_ALPHA)

        ;Tidy Up at end of each frame, otherwise memory use gets excessive in a short time.
        ;~  _GDIPlus_ImageDispose($hImage)
        _WinAPI_ReleaseDC(0, $hScrDC)
        _WinAPI_DeleteObject($hBitmap)
        _WinAPI_DeleteDC($hMemDC)

        ; By rights I should be using the const PropertyTagFrameDelay and geting the properties time delay between frames.
        ; I cheated , so shoot me...lol
        Sleep(100)

        $i += 1
    Until _IsPressed("1B") ;Esc to exit
EndFunc


Func terminate()
    _GDIPlus_ImageDispose($hImage)
    _GDIPlus_Shutdown()
    Exit (0)
EndFunc  ;==>terminate
Link to comment
Share on other sites

  • 2 weeks later...

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...