Advertisement
tabnation

gif gui

Jan 5th, 2022
155
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.47 KB | None
  1. #NoEnv
  2. #Include Gdip_All.ahk
  3. SetBatchLines, -1
  4. filePath := "C:\Users\Thom\Desktop\fireworks.gif" ; specify the file path to gif
  5. ;FileSelectFile, filePath, 2, %A_ScriptDir%, Select a file
  6.  
  7.  
  8. pToken := Gdip_Startup()
  9. OnExit, Exit
  10.  
  11. exStyles := (WS_EX_COMPOSITED := 0x02000000) | (WS_EX_LAYERED := 0x80000)
  12. Gui, New, +E%exStyles%
  13. Gui, Add, Picture, y10 hwndhwndGif1, % filePath
  14. ;Gui, Add, Button, xp y+10 gPlayPause hwndhwndPlayPause, Happy New Years
  15. gif1 := new Gif(filePath, hwndGif1)
  16. Gui, Show, AutoSize, Animated gif
  17.  
  18. goto PlayPause
  19. return
  20. GuiClose:
  21. ExitApp
  22.  
  23. PlayPause:
  24. isPlaying := gif1.isPlaying
  25. GuiControl,, % hwndPlayPause, % (isPlaying) ? "Play" : "Pause"
  26. if (!isPlaying) {
  27. gif1.Play()
  28. } else {
  29. gif1.Pause()
  30. }
  31. return
  32.  
  33. ;######################################################
  34.  
  35. Exit:
  36. Gdip_ShutDown(pToken)
  37. ExitApp
  38. return
  39.  
  40. ;######################################################
  41.  
  42. class Gif
  43. {
  44. __New(file, hwnd, cycle := true)
  45. {
  46. this.file := file
  47. this.hwnd := hwnd
  48. this.cycle := cycle
  49. this.pBitmap := Gdip_CreateBitmapFromFile(this.file)
  50. Gdip_GetImageDimensions(this.pBitmap, width, height)
  51. this.width := width, this.height := height
  52. this.isPlaying := false
  53.  
  54. DllCall("Gdiplus\GdipImageGetFrameDimensionsCount", "ptr", this.pBitmap, "uptr*", frameDimensions)
  55. this.SetCapacity("dimensionIDs", 16*frameDimensions)
  56. DllCall("Gdiplus\GdipImageGetFrameDimensionsList", "ptr", this.pBitmap, "uptr", this.GetAddress("dimensionIDs"), "int", frameDimensions)
  57. DllCall("Gdiplus\GdipImageGetFrameCount", "ptr", this.pBitmap, "uptr", this.GetAddress("dimensionIDs"), "int*", count)
  58. this.frameCount := count
  59. this.frameCurrent := -1
  60. this.frameDelay := this.GetFrameDelay(this.pBitmap)
  61. this._Play("")
  62. }
  63.  
  64. ; Return a zero-based array, containing the frames delay (in milliseconds)
  65. GetFrameDelay(pImage) {
  66. static PropertyTagFrameDelay := 0x5100
  67.  
  68. DllCall("Gdiplus\GdipGetPropertyItemSize", "Ptr", pImage, "UInt", PropertyTagFrameDelay, "UInt*", ItemSize)
  69. VarSetCapacity(Item, ItemSize, 0)
  70. DllCall("Gdiplus\GdipGetPropertyItem" , "Ptr", pImage, "UInt", PropertyTagFrameDelay, "UInt", ItemSize, "Ptr", &Item)
  71.  
  72. PropLen := NumGet(Item, 4, "UInt")
  73. PropVal := NumGet(Item, 8 + A_PtrSize, "UPtr")
  74.  
  75. outArray := []
  76. Loop, % PropLen//4 {
  77. if !n := NumGet(PropVal+0, (A_Index-1)*4, "UInt")
  78. n := 10
  79. outArray[A_Index-1] := n * 10
  80. }
  81. return outArray
  82. }
  83.  
  84. Play()
  85. {
  86. this.isPlaying := true
  87. fn := this._Play.Bind(this)
  88. this._fn := fn
  89. SetTimer, % fn, -1
  90. }
  91.  
  92. Pause()
  93. {
  94. this.isPlaying := false
  95. fn := this._fn
  96. SetTimer, % fn, Delete
  97. }
  98.  
  99. _Play(mode := "set")
  100. {
  101. this.frameCurrent := mod(++this.frameCurrent, this.frameCount)
  102. DllCall("Gdiplus\GdipImageSelectActiveFrame", "ptr", this.pBitmap, "uptr", this.GetAddress("dimensionIDs"), "int", this.frameCurrent)
  103. hBitmap := Gdip_CreateHBITMAPFromBitmap(this.pBitmap)
  104. SetImage(this.hwnd, hBitmap)
  105. DeleteObject(hBitmap)
  106. if (mode = "set" && this.frameCurrent < (this.cycle ? 0xFFFFFFFF : this.frameCount - 1)) {
  107. fn := this._fn
  108. SetTimer, % fn, % -1 * this.frameDelay[this.frameCurrent]
  109. }
  110. }
  111.  
  112. __Delete()
  113. {
  114. Gdip_DisposeImage(this.pBitmap)
  115. Object.Delete("dimensionIDs")
  116. }
  117. }
Advertisement
RAW Paste Data Copied
Advertisement