I've been successful in making my animated gif work!
Thanks to PhiLho, bigtime. I have one problem though and I've asked on the help section but there have been no replies, I'm thinking because I asked for help incorrectly.
My problem is not making the gif animate, it is placing the working code into my existing GUI. I've tried placing it in many different places (at the beginning, right after the gui is created, at the middle, at the end) and I've tried using #FileInclude from my GUI and from the working gif code but nothing "marries" the two chunks of code so it works together.
I cannot, for the life of me, understand how to incorporate this into my existing GUI.
You will need these three files in the same dir to run this altered demo (credits and thanks to PhiLho):
hal.gif
AniGIF.dll
Control_AniGif.ahk
This is the image, named hal.gif:
...you need the AniGIF.dll file to be in your script dir, download here:
http://autohotkey.net/~PhiLho/AniGIF.dll
Here is the altered GUI code in which it works, THANK YOU PHILHO btw!!!:
(name it Control_AniGif.ahk)
Code:
/**
* Control creation: you have to provide the ID of the GUI in which the control goes,
* its position (_x, _y) and size (_w, _h) and optionally additional styles,
* made of a string with keywords:
* - autosize to make the control adapts to the Gif size
* - center to center the Gif in the control
* - hyperlink to allow clicking on the control and opening the URL defined later
* Note that the required DLL is loaded automatically on first call.
*/
AniGif_CreateControl(_guiHwnd, _x, _y, _w, _h, _style="0")
{
local hAniGif, agHwnd
local msg, style
static $bFirstCall := true
If ($bFirstCall)
{
$bFirstCall := false
; It will be unloaded at script end
hAniGif := DllCall("LoadLibrary", "Str", "AniGif.dll")
}
style := 0
style := 0x50000000 | style
; http://msdn.microsoft.com/library/en-us/winui/winui/windowsuserinterface/windowing/windows/windowreference/windowfunctions/createwindowex.asp
agHwnd := DLLCall("CreateWindowEx"
, "UInt", 0 ; Style, can be WS_EX_CLIENTEDGE = 0x200
, "Str", "AniGIF" ; Class Name
, "Str", "AnimatedGif" ; Window name
, "UInt", style ; Window style
, "Int", _x ; X position
, "Int", _y ; Y position
, "Int", _w ; Width
, "Int", _h ; Height
, "UInt", _guiHwnd ; Handle of parent
, "UInt", 0 ; Menu
, "UInt", 0 ; hInstance of the module registering the component's class
, "UInt", 0) ; User defined style
If (ErrorLevel != 0 or agHwnd = 0)
{
msg = %msg% Cannot create animated gif
Gosub AniGif_CreateControl_CleanUp
Return msg
}
Return agHwnd
AniGif_CreateControl_CleanUp: ; In case of error
Return
}
/**
* Function to call before exiting or destroying the GUI.
*/
AniGif_DestroyControl(_agHwnd)
{
If (_agHwnd != 0)
{
AniGif_UnloadGif(_agHwnd)
DllCall("DestroyWindow", "UInt", _agHwnd)
}
}
;AniGIF control messages
; WM_USER := 0x400 ; 1024
; WAGM_BASE := WM_USER+1000 ; 2024
/**
* After control creation, allows to load the indicated file.
*/
AniGif_LoadGifFromFile(_agHwnd, _gifFile)
{
; WAGM_LOADGIFFROMFILE EQU WAGM_BASE+0 ;wParam:N/A, lParam:lpFileName
SendMessage 2024, 0, &_gifFile, , ahk_id %_agHwnd%
}
AniGif_UnloadGif(_agHwnd)
{
; WAGM_UNLOADGIF EQU WAGM_BASE+2 ;wParam:N/A, lParam:N/A
SendMessage 2026, 0, 0, , ahk_id %_agHwnd%
}
; (comment from Aaron: I've tried removing this next part and adding to other GUI with no success)
;-----8<----- For real use, just remove the part below before including the file ----------
; Run test code only if the file is ran standalone
If (A_ScriptName = "Control_AniGif.ahk")
{
Gui +LastFound
guiID := WinExist()
hAniGif1 := AniGif_CreateControl(guiID, 5, 5, 90, 90)
hAniGif2 := AniGif_CreateControl(guiID, 892, 5, 90, 90)
If hAniGif1 is not integer
MsgBox %hAniGif1%
If hAniGif2 is not integer
MsgBox %hAniGif2%
; this makes a working GUI for the gif
Gui Show, w987 h99, AniGif demo
Gui, Color, Red
;~ AniGif_LoadGifFromFile(hAniGif1, A_ScriptDir . "\hal.gif")
WideCharToMultiByte("hal.gif",sFileName)
AniGif_LoadGifFromFile(hAniGif1, sFileName)
;~ AniGif_LoadGifFromFile(hAniGif2, A_ScriptDir . "\hal.gif")
WideCharToMultiByte("hal.gif",sFileName)
AniGif_LoadGifFromFile(hAniGif2, sFileName)
Return
WideCharToMultiByte(wChar,Byref sChar) {
VarSetCapacity(sChar,StrLen(wChar)*2)
return DllCall("WideCharToMultiByte", "Uint", 0, "Uint", 0, "str", wChar, "int", -1, "str", sChar, "int", StrLen(wChar)*2, "Uint", 0, "Uint", 0)
}
}
Can I please have someone's help with this? It needs to go in my GUI called "Aaron's Super Google Search"
Thank you very much
Aaron