GuiAVI.au3 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. #include-once
  2. #include "AVIConstants.au3"
  3. #include "Memory.au3"
  4. #include "SendMessage.au3"
  5. #include "UDFGlobalID.au3"
  6. #include "WinAPIConv.au3"
  7. #include "WinAPIInternals.au3"
  8. #include "WinAPISysInternals.au3"
  9. ; #INDEX# =======================================================================================================================
  10. ; Title .........: Animation
  11. ; AutoIt Version : 3.3.14.5
  12. ; Language ......: English
  13. ; Description ...: Functions that assist with AVI control management.
  14. ; An animation control is a window that displays an Audio-Video Interleaved (AVI) clip. An AVI clip is a series
  15. ; of bitmap frames like a movie. Animation controls can only display AVI clips that do not contain audio. One
  16. ; common use for an animation control is to indicate system activity during a lengthy operation. This is
  17. ; possible because the operation thread continues executing while the AVI clip is displayed. For example, the
  18. ; Find dialog box of Microsoft Windows Explorer displays a moving magnifying glass as the system searches for a
  19. ; file.
  20. ;
  21. ; If you are using comctl32.dll version 6 the thread is not supported, therefore make sure that your application
  22. ; does not block the UI or the animation will not occur. An animation control can display an AVI clip
  23. ; originating from either an uncompressed AVI file or from an AVI file that was compressed using run length
  24. ; (BI_RLE8) encoding. You can add the AVI clip to your application as an AVI resource, or the clip can accompany
  25. ; your application as a separate AVI file.
  26. ;
  27. ; The AVI file, or resource, must not have a sound channel. The capabilities of the animation control are very
  28. ; limited and are subject to change. If you need a control to provide multimedia playback and recording
  29. ; capabilities for your application, you can use the MCIWnd control.
  30. ; Author(s) .....: Paul Campbell (PaulIA)
  31. ; Dll(s .........: user32.dll
  32. ; ===============================================================================================================================
  33. ; #VARIABLES# ===================================================================================================================
  34. Global $__g_hAVLastWnd
  35. ; ===============================================================================================================================
  36. ; #CONSTANTS# ===================================================================================================================
  37. Global Const $__AVICONSTANT_ClassName = "SysAnimate32"
  38. ; ===============================================================================================================================
  39. ; #CURRENT# =====================================================================================================================
  40. ; _GUICtrlAVI_Close
  41. ; _GUICtrlAVI_Create
  42. ; _GUICtrlAVI_Destroy
  43. ; _GUICtrlAVI_IsPlaying
  44. ; _GUICtrlAVI_Open
  45. ; _GUICtrlAVI_OpenEx
  46. ; _GUICtrlAVI_Play
  47. ; _GUICtrlAVI_Seek
  48. ; _GUICtrlAVI_Show
  49. ; _GUICtrlAVI_Stop
  50. ; ===============================================================================================================================
  51. ; #FUNCTION# ====================================================================================================================
  52. ; Author ........: Paul Campbell (PaulIA)
  53. ; Modified.......: Gary Frost
  54. ; ===============================================================================================================================
  55. Func _GUICtrlAVI_Close($hWnd)
  56. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  57. Local $iRet = _SendMessage($hWnd, $ACM_OPENA)
  58. Return SetError(@error, @extended, $iRet <> 0)
  59. EndFunc ;==>_GUICtrlAVI_Close
  60. ; #FUNCTION# ====================================================================================================================
  61. ; Author ........: Paul Campbell (PaulIA)
  62. ; Modified.......: Gary Frost (Added params, Added Open calls "sets the avi to 1st frame")
  63. ; ===============================================================================================================================
  64. Func _GUICtrlAVI_Create($hWnd, $sFilePath = "", $iSubFileID = -1, $iX = 0, $iY = 0, $iWidth = 0, $iHeight = 0, $iStyle = 0x00000006, $iExStyle = 0x00000000)
  65. If Not IsHWnd($hWnd) Then Return SetError(1, 0, 0) ; Invalid Window handle for 1st parameter
  66. If Not IsString($sFilePath) Then Return SetError(2, 0, 0) ; 2nd parameter not a string for _GUICtrlAVI_Create
  67. $iStyle = BitOR($iStyle, $__UDFGUICONSTANT_WS_CHILD, $__UDFGUICONSTANT_WS_VISIBLE)
  68. Local $nCtrlID = __UDF_GetNextGlobalID($hWnd)
  69. If @error Then Return SetError(@error, @extended, 0)
  70. Local $hAVI = _WinAPI_CreateWindowEx($iExStyle, $__AVICONSTANT_ClassName, "", $iStyle, $iX, $iY, $iWidth, $iHeight, $hWnd, $nCtrlID)
  71. If $iSubFileID <> -1 And $sFilePath <> "" Then
  72. _GUICtrlAVI_OpenEx($hAVI, $sFilePath, $iSubFileID)
  73. ElseIf $sFilePath <> "" Then
  74. _GUICtrlAVI_Open($hAVI, $sFilePath)
  75. EndIf
  76. Return $hAVI
  77. EndFunc ;==>_GUICtrlAVI_Create
  78. ; #FUNCTION# ====================================================================================================================
  79. ; Author ........: Gary Frost (gafrost)
  80. ; Modified.......:
  81. ; ===============================================================================================================================
  82. Func _GUICtrlAVI_Destroy(ByRef $hWnd)
  83. If Not _WinAPI_IsClassName($hWnd, $__AVICONSTANT_ClassName) Then Return SetError(2, 2, False)
  84. Local $iDestroyed = 0
  85. If IsHWnd($hWnd) Then
  86. If _WinAPI_InProcess($hWnd, $__g_hAVLastWnd) Then
  87. Local $nCtrlID = _WinAPI_GetDlgCtrlID($hWnd)
  88. Local $hParent = _WinAPI_GetParent($hWnd)
  89. $iDestroyed = _WinAPI_DestroyWindow($hWnd)
  90. Local $iRet = __UDF_FreeGlobalID($hParent, $nCtrlID)
  91. If Not $iRet Then
  92. ; can check for errors here if needed, for debug
  93. EndIf
  94. Else
  95. ; Not Allowed to Destroy Other Applications Control(s)
  96. Return SetError(1, 1, False)
  97. EndIf
  98. Else
  99. $iDestroyed = GUICtrlDelete($hWnd)
  100. EndIf
  101. If $iDestroyed Then $hWnd = 0
  102. Return $iDestroyed <> 0
  103. EndFunc ;==>_GUICtrlAVI_Destroy
  104. ; #FUNCTION# ====================================================================================================================
  105. ; Author ........: Gary Frost
  106. ; Modified.......:
  107. ; ===============================================================================================================================
  108. Func _GUICtrlAVI_IsPlaying($hWnd)
  109. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  110. Return _SendMessage($hWnd, $ACM_ISPLAYING) <> 0
  111. EndFunc ;==>_GUICtrlAVI_IsPlaying
  112. ; #FUNCTION# ====================================================================================================================
  113. ; Author ........: Paul Campbell (PaulIA)
  114. ; Modified.......: Gary Frost (Added seek "sets the avi to 1st frame")
  115. ; ===============================================================================================================================
  116. Func _GUICtrlAVI_Open($hWnd, $sFileName)
  117. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  118. Local $iRet
  119. If _WinAPI_InProcess($hWnd, $__g_hAVLastWnd) Then
  120. $iRet = _SendMessage($hWnd, $ACM_OPENW, 0, $sFileName, 0, "wparam", "wstr")
  121. Else
  122. Local $tBuffer = DllStructCreate("wchar Text[" & StringLen($sFileName) + 1 & "]")
  123. DllStructSetData($tBuffer, "Text", $sFileName)
  124. Local $tMemMap
  125. _MemInit($hWnd, DllStructGetSize($tBuffer), $tMemMap)
  126. _MemWrite($tMemMap, $tBuffer)
  127. $iRet = _SendMessage($hWnd, $ACM_OPENW, True, $tBuffer, 0, "wparam", "struct*")
  128. _MemFree($tMemMap)
  129. EndIf
  130. If $iRet <> 0 Then _GUICtrlAVI_Seek($hWnd, 0)
  131. Return SetError(@error, @extended, $iRet <> 0)
  132. EndFunc ;==>_GUICtrlAVI_Open
  133. ; #FUNCTION# ====================================================================================================================
  134. ; Author ........: Paul Campbell (PaulIA)
  135. ; Modified.......: Gary Frost (Added seek "sets the avi to 1st frame")
  136. ; ===============================================================================================================================
  137. Func _GUICtrlAVI_OpenEx($hWnd, $sFileName, $iResourceID)
  138. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  139. Local $hInst = _WinAPI_LoadLibrary($sFileName)
  140. If @error Then Return SetError(@error, @extended, False)
  141. Local $iRet = _SendMessage($hWnd, $ACM_OPENW, $hInst, $iResourceID)
  142. _WinAPI_FreeLibrary($hInst)
  143. If $iRet <> 0 Then _GUICtrlAVI_Seek($hWnd, 0)
  144. Return SetError(@error, @extended, $iRet <> 0)
  145. EndFunc ;==>_GUICtrlAVI_OpenEx
  146. ; #FUNCTION# ====================================================================================================================
  147. ; Author ........: Paul Campbell (PaulIA)
  148. ; Modified.......: Gary Frost
  149. ; ===============================================================================================================================
  150. Func _GUICtrlAVI_Play($hWnd, $iFrom = 0, $iTo = -1, $iRepeat = -1)
  151. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  152. Local $iRet = _SendMessage($hWnd, $ACM_PLAY, $iRepeat, _WinAPI_MakeLong($iFrom, $iTo))
  153. Return SetError(@error, @extended, $iRet <> 0)
  154. EndFunc ;==>_GUICtrlAVI_Play
  155. ; #FUNCTION# ====================================================================================================================
  156. ; Author ........: Paul Campbell (PaulIA)
  157. ; Modified.......: Gary Frost
  158. ; ===============================================================================================================================
  159. Func _GUICtrlAVI_Seek($hWnd, $iFrame)
  160. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  161. Local $iRet = _SendMessage($hWnd, $ACM_PLAY, 1, _WinAPI_MakeLong($iFrame, $iFrame))
  162. Return SetError(@error, @extended, $iRet <> 0)
  163. EndFunc ;==>_GUICtrlAVI_Seek
  164. ; #FUNCTION# ====================================================================================================================
  165. ; Author ........: Gary Frost (gafrost)
  166. ; Modified.......:
  167. ; ===============================================================================================================================
  168. Func _GUICtrlAVI_Show($hWnd, $iState)
  169. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  170. If $iState <> @SW_HIDE And $iState <> @SW_SHOW Then Return SetError(1, 1, 0)
  171. Return _WinAPI_ShowWindow($hWnd, $iState)
  172. EndFunc ;==>_GUICtrlAVI_Show
  173. ; #FUNCTION# ====================================================================================================================
  174. ; Author ........: Paul Campbell (PaulIA)
  175. ; Modified.......: Gary Frost
  176. ; ===============================================================================================================================
  177. Func _GUICtrlAVI_Stop($hWnd)
  178. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  179. Local $iRet = _SendMessage($hWnd, $ACM_STOP)
  180. Return SetError(@error, @extended, $iRet <> 0)
  181. EndFunc ;==>_GUICtrlAVI_Stop