;~ ===================================================================================================================================== ;BinaryImage.au3 ;~ ===================================================================================================================================== Func _SetImageBinaryToCtrl($CtrlId, ByRef $Binary) Local $picdata = Binary($Binary) ; Fetch the Data Local $piclength = BinaryLen($picdata) ; Get Length Local $picstruct = DllStructCreate("byte[" & $piclength & "]") DllStructSetData($picstruct,1,$picdata) Local $picmemory = DllStructGetPtr($picstruct) _SetMemoryImageToCtrl($CtrlId, $picmemory, $piclength) DllStructSetData($picstruct,1,0) $picstruct = "" EndFunc ; Authors: Zedna, based on code by Prog@ndy Func _SetMemoryImageToCtrl($CtrlId, $Pointer, $nSize) Local $hData, $pData, $pStream, $pBitmap, $hBitmap ; use GDI+ for converting to bitmap first $hData = _MemGlobalAlloc($nSize,2) $pData = _MemGlobalLock($hData) _MemMoveMemory($Pointer,$pData,$nSize) _MemGlobalUnlock($hData) $pStream = DllCall( "ole32.dll","int","CreateStreamOnHGlobal", "int",$hData, "long",1, "Int*",0) $pStream = $pStream[3] _GDIPlus_Startup() $pBitmap = DllCall($ghGDIPDll,"int","GdipCreateBitmapFromStream", "ptr",$pStream, "int*",0) $pBitmap = $pBitmap[2] $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($pBitmap) _SetBitmapToCtrl($CtrlId, $hBitmap) If @error Then SetError(3, 0, 0) _GDIPlus_BitmapDispose($pBitmap) _GDIPlus_Shutdown() _WinAPI_DeleteObject($pStream) _MemGlobalFree($hData) EndFunc ; internal helper function ; Out of resources.au3 :) 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 $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)) 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 Func _AnimateGifInAnotherThread($hGIFControl, $aArrayOfHandlesAndTimes) ; error(s) checkings is missing in this function ; Address of Sleep function Local $Sleep = DllCall("kernel32.dll", "ptr", "GetProcAddress", "ptr", _WinAPI_GetModuleHandle("kernel32.dll"), "str", "Sleep") $Sleep = $Sleep[0] ; Number of handles Local $iUbound = UBound($aArrayOfHandlesAndTimes) Local $iTransparent ; Going to generate assembly code now. ; Gif could be transparent. In that case will use SendMessageW function to draw frames. ; This is flickering (or could), but I don't know better. ; If not transparent DrawIconEx is used. No flickering there. If $iTransparent Then ; Address of SendMessageW function Local $SendMessageW = DllCall("kernel32.dll", "ptr", "GetProcAddress", "ptr", _WinAPI_GetModuleHandle("user32.dll"), "str", "SendMessageW") $SendMessageW = $SendMessageW[0] ; Will construct structure Local $tagCodeBuffer For $i = 1 To $iUbound $tagCodeBuffer &= "byte[39];" ; 39 bytes large parts Next $tagCodeBuffer &= "byte[5]" ; this is the closing part ; Create it Local $CodeBuffer = DllStructCreate($tagCodeBuffer) ; Structures created by DllStructCreate() have PAGE_READWRITE access protection. ; PAGE_EXECUTE_READWRITE ir required for this task. Allocating it: Local $RemoteCode = _MemVirtualAlloc(0, DllStructGetSize($CodeBuffer), $MEM_COMMIT, $PAGE_EXECUTE_READWRITE) ; Every part of assembly code is the same. Only icon handle is changing. ; Like this: For $i = 1 To $iUbound DllStructSetData($CodeBuffer, $i, _ "0x" & _ "68" & SwapEndian(0) & _ ; push lParam "68" & SwapEndian($aArrayOfHandlesAndTimes[$i - 1][0]) & _ ; push handle to the icon "68" & SwapEndian(368) & _ ; push STM_SETICON "68" & SwapEndian(GUICtrlGetHandle($hGIFControl)) & _ ; push HANDLE "B8" & SwapEndian($SendMessageW) & _ ; mov eax, SendMessageW "FFD0" & _ ; call eax "68" & SwapEndian($aArrayOfHandlesAndTimes[$i - 1][1]) & _ ; push Milliseconds "B8" & SwapEndian($Sleep) & _ ; call function Sleep "FFD0" _ ; call eax ) Next ; This is to say loop DllStructSetData($CodeBuffer, $iUbound + 1, _ "0x" & _ "E9" & SwapEndian(-($iUbound * 39 + 5)) & _ ; jump [start address] "C3" _ ; ret ) Else ; if not transparent ; Address of DrawIconEx function Local $DrawIconEx = DllCall("kernel32.dll", "ptr", "GetProcAddress", "ptr", _WinAPI_GetModuleHandle("user32.dll"), "str", "DrawIconEx") $DrawIconEx = $DrawIconEx[0] ; Structure job... Local $tagCodeBuffer For $i = 1 To $iUbound $tagCodeBuffer &= "byte[64];" ; this is a little larger than 39 bytes (more parameters) Next $tagCodeBuffer &= "byte[5]" ; last part ; Create structure Local $CodeBuffer = DllStructCreate($tagCodeBuffer) ; Allocate memory with PAGE_EXECUTE_READWRITE access protection. Local $RemoteCode = DllCall("kernel32.dll", "ptr", "VirtualAlloc", _ "ptr", 0, _ "dword", DllStructGetSize($CodeBuffer), _ "dword", 4096, _ ; MEM_COMMIT "dword", 64) ; PAGE_EXECUTE_READWRITE $RemoteCode = $RemoteCode[0] ; Handle of a display device context is required for DrawIconEx Local $hDC = _WinAPI_GetDC(GUICtrlGetHandle($hGIFControl)) ; Generate assembly code: For $i = 1 To $iUbound DllStructSetData($CodeBuffer, $i, _ "0x" & _ "68" & SwapEndian(3) & _ ; push Flags DI_NORMAL "68" & SwapEndian(0) & _ ; push FlickerFreeDraw "68" & SwapEndian(0) & _ ; push IfAniCur "68" & SwapEndian(0) & _ ; push Height "68" & SwapEndian(0) & _ ; push Width "68" & SwapEndian($aArrayOfHandlesAndTimes[$i - 1][0]) & _ ; push handle to the icon "68" & SwapEndian(0) & _ ; push Top "68" & SwapEndian(0) & _ ; push Left "68" & SwapEndian($hDC) & _ ; push DC "B8" & SwapEndian($DrawIconEx) & _ ; mov eax, DrawIconEx "FFD0" & _ ; call eax "68" & SwapEndian($aArrayOfHandlesAndTimes[$i - 1][1]) & _ ; push Milliseconds "B8" & SwapEndian($Sleep) & _ ; call function Sleep "FFD0" _ ; call eax ) Next ; Finish it: DllStructSetData($CodeBuffer, $iUbound + 1, _ "0x" & _ "E9" & SwapEndian(-($iUbound * 64 + 5)) & _ ; jump [start address] "C3" _ ; ret ) EndIf ; Move this to that... _MemMoveMemory(DllStructGetPtr($CodeBuffer), $RemoteCode, DllStructGetSize($CodeBuffer)) ; Create thread to execute in: Local $aCall = DllCall("kernel32.dll", "ptr", "CreateThread", "ptr", 0, "dword", 0, "ptr", $RemoteCode, "ptr", 0, "dword", 0, "dword*", 0) Local $hThread = $aCall[0] ; Will return handle to the new thread to have complete control: Return $hThread EndFunc ;==>_AnimateGifInAnotherThread Func SwapEndian($hex) Return Hex(BinaryMid(Binary($hex), 1, 4)) EndFunc ;==>SwapEndian Func _CreateArrayHIconsFromGIFBinaryImage($bBinary) ; ProgAndy's originally DllOpen("gdiplus.dll") Local $tBinary = DllStructCreate("byte[" & BinaryLen($bBinary) & "]") DllStructSetData($tBinary, 1, $bBinary) Local $a_hCall = DllCall("kernel32.dll", "hwnd", "GlobalAlloc", _ ; local version will work too (no difference in local and global heap) "dword", 2, _ ; LMEM_MOVEABLE "dword", DllStructGetSize($tBinary)) If @error Or Not $a_hCall[0] Then Return SetError(1, 0, "") EndIf Local $hMemory = $a_hCall[0] Local $a_pCall = DllCall("kernel32.dll", "ptr", "GlobalLock", "hwnd", $hMemory) If @error Or Not $a_pCall[0] Then DllCall("kernel32.dll", "int", "GlobalFree", "hwnd", $hMemory) Return SetError(2, 0, "") EndIf Local $pMemory = $a_pCall[0] DllCall("kernel32.dll", "none", "RtlMoveMemory", _ "ptr", $pMemory, _ "ptr", DllStructGetPtr($tBinary), _ "dword", DllStructGetSize($tBinary)) DllCall("kernel32.dll", "int", "GlobalUnlock", "hwnd", $hMemory) Local $a_iCall = DllCall("ole32.dll", "int", "CreateStreamOnHGlobal", _ "ptr", $pMemory, _ "int", 1, _ "ptr*", 0) If @error Or $a_iCall[0] Then DllCall("kernel32.dll", "int", "GlobalFree", "hwnd", $hMemory) Return SetError(3, 0, "") EndIf Local $pStream = $a_iCall[3] Local $tGdiplusStartupInput = DllStructCreate("dword GdiplusVersion;" & _ "ptr DebugEventCallback;" & _ "int SuppressBackgroundThread;" & _ "int SuppressExternalCodecs") DllStructSetData($tGdiplusStartupInput, "GdiplusVersion", 1) $a_iCall = DllCall("gdiplus.dll", "dword", "GdiplusStartup", _ "dword*", 0, _ "ptr", DllStructGetPtr($tGdiplusStartupInput), _ "ptr", 0) If @error Or $a_iCall[0] Then DllCall("kernel32.dll", "int", "GlobalFree", "hwnd", $hMemory) Return SetError(4, 0, "") EndIf Local $hGDIplus = $a_iCall[1] $a_iCall = DllCall("gdiplus.dll", "dword", "GdipCreateBitmapFromStream", _ ; GdipLoadImageFromStream "ptr", $pStream, _ "ptr*", 0) If @error Or $a_iCall[0] Then DllCall("gdiplus.dll", "none", "GdiplusShutdown", "dword*", $hGDIplus) DllCall("kernel32.dll", "int", "GlobalFree", "hwnd", $hMemory) Return SetError(5, 0, "") EndIf Local $pBitmap = $a_iCall[2] $a_iCall = DllCall("gdiplus.dll", "dword", "GdipGetImageDimension", _ "ptr", $pBitmap, _ "float*", 0, _ "float*", 0) If @error Or $a_iCall[0] Then DllCall("gdiplus.dll", "dword", "GdipDisposeImage", "ptr", $pBitmap) DllCall("gdiplus.dll", "none", "GdiplusShutdown", "dword*", $hGDIplus) DllCall("kernel32.dll", "int", "GlobalFree", "hwnd", $hMemory) Return SetError(5, 0, "") EndIf $iWidth = $a_iCall[2] $iHeight = $a_iCall[3] Local $a_iCall = DllCall("gdiplus.dll", "dword", "GdipImageGetFrameDimensionsCount", _ "ptr", $pBitmap, _ "dword*", 0) If @error Or $a_iCall[0] Then DllCall("gdiplus.dll", "dword", "GdipDisposeImage", "ptr", $pBitmap) DllCall("gdiplus.dll", "none", "GdiplusShutdown", "dword*", $hGDIplus) DllCall("kernel32.dll", "int", "GlobalFree", "hwnd", $hMemory) Return SetError(8, 0, "") EndIf Local $iFrameDimensionsCount = $a_iCall[2] Local $tGUID = DllStructCreate("int;short;short;byte[8]") $a_iCall = DllCall("gdiplus.dll", "dword", "GdipImageGetFrameDimensionsList", _ "ptr", $pBitmap, _ "ptr", DllStructGetPtr($tGUID), _ "dword", $iFrameDimensionsCount) If @error Or $a_iCall[0] Then DllCall("gdiplus.dll", "dword", "GdipDisposeImage", "ptr", $pBitmap) DllCall("gdiplus.dll", "none", "GdiplusShutdown", "dword*", $hGDIplus) DllCall("kernel32.dll", "int", "GlobalFree", "hwnd", $hMemory) Return SetError(9, 0, "") EndIf $a_iCall = DllCall("gdiplus.dll", "dword", "GdipImageGetFrameCount", _ "ptr", $pBitmap, _ "ptr", DllStructGetPtr($tGUID), _ "dword*", 0) If @error Or $a_iCall[0] Then DllCall("gdiplus.dll", "dword", "GdipDisposeImage", "ptr", $pBitmap) DllCall("gdiplus.dll", "none", "GdiplusShutdown", "dword*", $hGDIplus) DllCall("kernel32.dll", "int", "GlobalFree", "hwnd", $hMemory) Return SetError(10, 0, "") EndIf Local $iFrameCount = $a_iCall[3] Local $aHBitmaps[$iFrameCount][3] For $i = 0 To $iFrameCount - 1 $a_iCall = DllCall("gdiplus.dll", "dword", "GdipImageSelectActiveFrame", _ "ptr", $pBitmap, _ "ptr", DllStructGetPtr($tGUID), _ "dword", $i) If @error Or $a_iCall[0] Then $aHBitmaps[$i][0] = 0 ContinueLoop EndIf $a_iCall = DllCall("gdiplus.dll", "dword", "GdipCreateHICONFromBitmap", _ "ptr", $pBitmap, _ "hwnd*", 0) If @error Or $a_iCall[0] Then $aHBitmaps[$i][0] = 0 ContinueLoop EndIf $aHBitmaps[$i][0] = $a_iCall[2] Next $a_iCall = DllCall("gdiplus.dll", "dword", "GdipGetPropertyItemSize", _ "ptr", $pBitmap, _ "dword", 20736, _ ; PropertyTagFrameDelay "dword*", 0) If @error Or $a_iCall[0] Then DllCall("gdiplus.dll", "dword", "GdipDisposeImage", "ptr", $pBitmap) DllCall("gdiplus.dll", "none", "GdiplusShutdown", "dword*", $hGDIplus) DllCall("kernel32.dll", "int", "GlobalFree", "hwnd", $hMemory) Return SetError(11, 0, "") EndIf Local $iPropertyItemSize = $a_iCall[3] Local $tRawPropItem = DllStructCreate("byte[" & $iPropertyItemSize & "]") $a_iCall = DllCall("gdiplus.dll", "dword", "GdipGetPropertyItem", _ "ptr", $pBitmap, _ "dword", 20736, _ ; PropertyTagFrameDelay "dword", DllStructGetSize($tRawPropItem), _ "ptr", DllStructGetPtr($tRawPropItem)) If @error Or $a_iCall[0] Then DllCall("gdiplus.dll", "dword", "GdipDisposeImage", "ptr", $pBitmap) DllCall("gdiplus.dll", "none", "GdiplusShutdown", "dword*", $hGDIplus) DllCall("kernel32.dll", "int", "GlobalFree", "hwnd", $hMemory) Return SetError(12, 0, "") EndIf Local $tPropItem = DllStructCreate("int Id;" & _ "dword Length;" & _ "ushort Type;" & _ "ptr Value", _ DllStructGetPtr($tRawPropItem)) Local $iSize = DllStructGetData($tPropItem, "Length") / 4 ; 'Delay Time' is dword type Local $tPropertyData = DllStructCreate("dword[" & $iSize & "]", DllStructGetData($tPropItem, "Value")) For $i = 0 To $iFrameCount - 1 $aHBitmaps[$i][1] = DllStructGetData($tPropertyData, 1, $i + 1) * 10 ; 1 = 10 msec $aHBitmaps[$i][2] = $aHBitmaps[$i][1] ; read values If Not $aHBitmaps[$i][1] Then $aHBitmaps[$i][1] = 130 ; 0 is interpreted as 130 ms EndIf If $aHBitmaps[$i][1] < 50 Then ; will slow it down to prevent more extensive cpu usage $aHBitmaps[$i][1] = 50 EndIf Next $iTransparency = 1 ; predefining $a_iCall = DllCall("gdiplus.dll", "dword", "GdipBitmapGetPixel", _ "ptr", $pBitmap, _ "int", 0, _ ; left "int", 0, _ ; upper "dword*", 0) If @error Or $a_iCall[0] Then DllCall("gdiplus.dll", "dword", "GdipDisposeImage", "ptr", $pBitmap) DllCall("gdiplus.dll", "none", "GdiplusShutdown", "dword*", $hGDIplus) DllCall("kernel32.dll", "int", "GlobalFree", "hwnd", $hMemory) Return SetError(13, 0, "") EndIf If $a_iCall[4] > 16777215 Then $iTransparency = 0 EndIf DllCall("gdiplus.dll", "dword", "GdipDisposeImage", "ptr", $pBitmap) DllCall("gdiplus.dll", "none", "GdiplusShutdown", "dword*", $hGDIplus) DllCall("kernel32.dll", "int", "GlobalFree", "hwnd", $hMemory) Return SetError(0, 0, $aHBitmaps) EndFunc ;==>_CreateArrayHIconsFromGIFBinaryImage Func _CreateArrayHIconsFromGIFFile($sFile, ByRef $iWidth, ByRef $iHeight, ByRef $iTransparency) Local $a_hCall = DllCall("kernel32.dll", "hwnd", "CreateFileW", _ "wstr", $sFile, _ "dword", 0x80000000, _ ; GENERIC_READ "dword", 1, _ ; FILE_SHARE_READ "ptr", 0, _ "dword", 3, _ ; OPEN_EXISTING "dword", 0, _ ; SECURITY_ANONYMOUS "ptr", 0) If @error Or $a_hCall[0] = -1 Then Return SetError(1, 0, "") EndIf Local $hFile = $a_hCall[0] $a_hCall = DllCall("kernel32.dll", "ptr", "CreateFileMappingW", _ "hwnd", $hFile, _ "dword", 0, _ ; default security descriptor "dword", 2, _ ; PAGE_READONLY "dword", 0, _ "dword", 0, _ "ptr", 0) If @error Or Not $a_hCall[0] Then DllCall("kernel32.dll", "int", "CloseHandle", "hwnd", $hFile) Return SetError(2, 0, "") EndIf DllCall("kernel32.dll", "int", "CloseHandle", "hwnd", $hFile) Local $hFileMappingObject = $a_hCall[0] $a_hCall = DllCall("kernel32.dll", "ptr", "MapViewOfFile", _ "hwnd", $hFileMappingObject, _ "dword", 4, _ ; FILE_MAP_READ "dword", 0, _ "dword", 0, _ "dword", 0) If @error Or Not $a_hCall[0] Then DllCall("kernel32.dll", "int", "CloseHandle", "hwnd", $hFileMappingObject) Return SetError(3, 0, "") EndIf Local $pFile = $a_hCall[0] Local $iBufferSize = FileGetSize($sFile) Local $a_hCall = DllCall("kernel32.dll", "hwnd", "GlobalAlloc", _ "dword", 2, _ ; LMEM_MOVEABLE "dword", $iBufferSize) If @error Or Not $a_hCall[0] Then Return SetError(4, 0, "") EndIf Local $hMemory = $a_hCall[0] Local $a_pCall = DllCall("kernel32.dll", "ptr", "GlobalLock", "hwnd", $hMemory) If @error Or Not $a_pCall[0] Then DllCall("kernel32.dll", "int", "GlobalFree", "hwnd", $hMemory) Return SetError(5, 0, "") EndIf Local $pMemory = $a_pCall[0] DllCall("kernel32.dll", "none", "RtlMoveMemory", _ "ptr", $pMemory, _ "ptr", $pFile, _ "dword", $iBufferSize) If @error Then DllCall("kernel32.dll", "int", "GlobalUnlock", "hwnd", $hMemory) DllCall("kernel32.dll", "int", "UnmapViewOfFile", "ptr", $pFile) DllCall("kernel32.dll", "int", "CloseHandle", "hwnd", $hFileMappingObject) Return SetError(6, 0, "") EndIf DllCall("kernel32.dll", "int", "GlobalUnlock", "hwnd", $hMemory) DllCall("kernel32.dll", "int", "UnmapViewOfFile", "ptr", $pFile) DllCall("kernel32.dll", "int", "CloseHandle", "hwnd", $hFileMappingObject) Local $a_iCall = DllCall("ole32.dll", "int", "CreateStreamOnHGlobal", _ "ptr", $pMemory, _ "int", 1, _ "ptr*", 0) If @error Or $a_iCall[0] Then DllCall("kernel32.dll", "int", "GlobalFree", "hwnd", $hMemory) Return SetError(7, 0, "") EndIf Local $pStream = $a_iCall[3] Local $tGdiplusStartupInput = DllStructCreate("dword GdiplusVersion;" & _ "ptr DebugEventCallback;" & _ "int SuppressBackgroundThread;" & _ "int SuppressExternalCodecs") DllStructSetData($tGdiplusStartupInput, "GdiplusVersion", 1) $a_iCall = DllCall("gdiplus.dll", "dword", "GdiplusStartup", _ "dword*", 0, _ "ptr", DllStructGetPtr($tGdiplusStartupInput), _ "ptr", 0) If @error Or $a_iCall[0] Then DllCall("kernel32.dll", "int", "GlobalFree", "hwnd", $hMemory) Return SetError(8, 0, "") EndIf Local $hGDIplus = $a_iCall[1] $a_iCall = DllCall("gdiplus.dll", "dword", "GdipCreateBitmapFromStream", _ ; GdipLoadImageFromStream "ptr", $pStream, _ "ptr*", 0) If @error Or $a_iCall[0] Then DllCall("gdiplus.dll", "none", "GdiplusShutdown", "dword*", $hGDIplus) DllCall("kernel32.dll", "int", "GlobalFree", "hwnd", $hMemory) Return SetError(9, 0, "") EndIf Local $pBitmap = $a_iCall[2] $a_iCall = DllCall("gdiplus.dll", "dword", "GdipGetImageDimension", _ "ptr", $pBitmap, _ "float*", 0, _ "float*", 0) If @error Or $a_iCall[0] Then DllCall("gdiplus.dll", "dword", "GdipDisposeImage", "ptr", $pBitmap) DllCall("gdiplus.dll", "none", "GdiplusShutdown", "dword*", $hGDIplus) DllCall("kernel32.dll", "int", "GlobalFree", "hwnd", $hMemory) Return SetError(10, 0, "") EndIf $iWidth = $a_iCall[2] $iHeight = $a_iCall[3] Local $a_iCall = DllCall("gdiplus.dll", "dword", "GdipImageGetFrameDimensionsCount", _ "ptr", $pBitmap, _ "dword*", 0) If @error Or $a_iCall[0] Then DllCall("gdiplus.dll", "dword", "GdipDisposeImage", "ptr", $pBitmap) DllCall("gdiplus.dll", "none", "GdiplusShutdown", "dword*", $hGDIplus) DllCall("kernel32.dll", "int", "GlobalFree", "hwnd", $hMemory) Return SetError(11, 0, "") EndIf Local $iFrameDimensionsCount = $a_iCall[2] Local $tGUID = DllStructCreate("int;short;short;byte[8]") $a_iCall = DllCall("gdiplus.dll", "dword", "GdipImageGetFrameDimensionsList", _ "ptr", $pBitmap, _ "ptr", DllStructGetPtr($tGUID), _ "dword", $iFrameDimensionsCount) If @error Or $a_iCall[0] Then DllCall("gdiplus.dll", "dword", "GdipDisposeImage", "ptr", $pBitmap) DllCall("gdiplus.dll", "none", "GdiplusShutdown", "dword*", $hGDIplus) DllCall("kernel32.dll", "int", "GlobalFree", "hwnd", $hMemory) Return SetError(12, 0, "") EndIf $a_iCall = DllCall("gdiplus.dll", "dword", "GdipImageGetFrameCount", _ "ptr", $pBitmap, _ "ptr", DllStructGetPtr($tGUID), _ "dword*", 0) If @error Or $a_iCall[0] Then DllCall("gdiplus.dll", "dword", "GdipDisposeImage", "ptr", $pBitmap) DllCall("gdiplus.dll", "none", "GdiplusShutdown", "dword*", $hGDIplus) DllCall("kernel32.dll", "int", "GlobalFree", "hwnd", $hMemory) Return SetError(13, 0, "") EndIf Local $iFrameCount = $a_iCall[3] Local $aHBitmaps[$iFrameCount][3] For $i = 0 To $iFrameCount - 1 $a_iCall = DllCall("gdiplus.dll", "dword", "GdipImageSelectActiveFrame", _ "ptr", $pBitmap, _ "ptr", DllStructGetPtr($tGUID), _ "dword", $i) If @error Or $a_iCall[0] Then $aHBitmaps[$i][0] = 0 ContinueLoop EndIf $a_iCall = DllCall("gdiplus.dll", "dword", "GdipCreateHICONFromBitmap", _ "ptr", $pBitmap, _ "hwnd*", 0) If @error Or $a_iCall[0] Then $aHBitmaps[$i][0] = 0 ContinueLoop EndIf $aHBitmaps[$i][0] = $a_iCall[2] Next $a_iCall = DllCall("gdiplus.dll", "dword", "GdipGetPropertyItemSize", _ "ptr", $pBitmap, _ "dword", 20736, _ ; PropertyTagFrameDelay "dword*", 0) If @error Or $a_iCall[0] Then DllCall("gdiplus.dll", "dword", "GdipDisposeImage", "ptr", $pBitmap) DllCall("gdiplus.dll", "none", "GdiplusShutdown", "dword*", $hGDIplus) DllCall("kernel32.dll", "int", "GlobalFree", "hwnd", $hMemory) Return SetError(14, 0, "") EndIf Local $iPropertyItemSize = $a_iCall[3] Local $tRawPropItem = DllStructCreate("byte[" & $iPropertyItemSize & "]") $a_iCall = DllCall("gdiplus.dll", "dword", "GdipGetPropertyItem", _ "ptr", $pBitmap, _ "dword", 20736, _ ; PropertyTagFrameDelay "dword", DllStructGetSize($tRawPropItem), _ "ptr", DllStructGetPtr($tRawPropItem)) If @error Or $a_iCall[0] Then DllCall("gdiplus.dll", "dword", "GdipDisposeImage", "ptr", $pBitmap) DllCall("gdiplus.dll", "none", "GdiplusShutdown", "dword*", $hGDIplus) DllCall("kernel32.dll", "int", "GlobalFree", "hwnd", $hMemory) Return SetError(15, 0, "") EndIf Local $tPropItem = DllStructCreate("int Id;" & _ "dword Length;" & _ "ushort Type;" & _ "ptr Value", _ DllStructGetPtr($tRawPropItem)) Local $iSize = DllStructGetData($tPropItem, "Length") / 4 ; 'Delay Time' is dword type Local $tPropertyData = DllStructCreate("dword[" & $iSize & "]", DllStructGetData($tPropItem, "Value")) For $i = 0 To $iFrameCount - 1 $aHBitmaps[$i][1] = DllStructGetData($tPropertyData, 1, $i + 1) * 10 ; 1 = 10 msec $aHBitmaps[$i][2] = $aHBitmaps[$i][1] ; read values If Not $aHBitmaps[$i][1] Then $aHBitmaps[$i][1] = 130 ; 0 is interpreted as 130 ms EndIf If $aHBitmaps[$i][1] < 50 Then ; will slow it down to prevent more extensive cpu usage $aHBitmaps[$i][1] = 50 EndIf Next $iTransparency = 1 ; predefining $a_iCall = DllCall("gdiplus.dll", "dword", "GdipBitmapGetPixel", _ "ptr", $pBitmap, _ "int", 0, _ ; left "int", 0, _ ; upper "dword*", 0) If @error Or $a_iCall[0] Then DllCall("gdiplus.dll", "dword", "GdipDisposeImage", "ptr", $pBitmap) DllCall("gdiplus.dll", "none", "GdiplusShutdown", "dword*", $hGDIplus) DllCall("kernel32.dll", "int", "GlobalFree", "hwnd", $hMemory) Return SetError(16, 0, "") EndIf If $a_iCall[4] > 16777215 Then $iTransparency = 0 EndIf DllCall("gdiplus.dll", "dword", "GdipDisposeImage", "ptr", $pBitmap) DllCall("gdiplus.dll", "none", "GdiplusShutdown", "dword*", $hGDIplus) DllCall("kernel32.dll", "int", "GlobalFree", "hwnd", $hMemory) Return SetError(0, 0, $aHBitmaps) EndFunc