' ---------------------------------------
' Adding a Simple AVI Animation CommCtrl
' By Don <don67geo@yahoo.com>
' ---------------------------------------
$APPTYPE GUI: $TYPECHECK ON

$DEFINE ACS_TRANSPARENT 2
$DEFINE ACM_OPEN        1124
$DEFINE ACM_PLAY        1125
$DEFINE ACM_STOP        1126
$DEFINE WS_VISIBLE      &H10000000
$DEFINE WS_CHILD        &H40000000

$DEFINE AVIWidth        272
$DEFINE AVIHeight       60

DECLARE FUNCTION CreateWindowEx LIB "USER32" _
        ALIAS "CreateWindowExA" _
        (dl1 AS LONG, BYVAL dl2 AS STRING, dl3 AS LONG, _
         dl4 AS LONG, dl5 AS LONG, dl6 AS LONG, _
         dl7 AS LONG, dl8 AS LONG, dl9 AS LONG, _
         dl10 AS LONG, dl11 AS LONG, dl12 AS LONG) _
         AS LONG

DECLARE SUB LoadMe
DECLARE SUB SwitchMe (key as byte, sender as QFORM)
DECLARE SUB SizeMe
DECLARE SUB UnLoadMe

DEFLNG hAnimation, hSwitch
DEFSTR AVIStream$ = "anicopy.avi"

CREATE Me AS QFORM
	Borderstyle = 3
    Caption = "AVI Animation Control Demo"
    Height  = 120
    Width   = 278
    Center
    CREATE MySB AS QSTATUSBAR
      AddPanels "Loading..."
    END CREATE
    OnClick = SwitchMe
    OnKeyDown = SwitchMe
    OnClose   = UnloadMe
    OnResize  = SizeMe
    OnShow    = LoadMe
    ShowModal
END CREATE


SUB LoadMe
  CALL SizeMe  ' Resize to fit all WIN version at runtime.
  hAnimation = CreateWindowEx (0, "SysAnimate32", 0, _
               WS_CHILD OR WS_VISIBLE OR ACS_TRANSPARENT, _
               0,0,AVIWidth,AVIHeight, Me.handle, 0, 0, 0)

  IF (hAnimation) THEN
     SendMessage(hAnimation, ACM_OPEN, 0, VARPTR(AVIStream$))
     SendMessage(hAnimation, ACM_PLAY,-1,-1)
     MySB.Panel(0).Caption = "Click on AVI to PLAY/STOP"
  ELSE
     SHOWMESSAGE "Fail to create Animation control!"
     MySB.Panel(0).Caption = "Fail to create Animation control!"
  END IF
END SUB

SUB SizeMe

  Me.Width = (Me.Width - Me.ClientWidth) + AVIWidth
  Me.Height = (Me.Height - Me.ClientHeight) + AVIHeight + MySB.Height
END SUB

SUB SwitchMe (key as byte, sender as QFORM)
  hSwitch = ABS(hSwitch-1)
  IF key = 27 THEN 	' ESC to Exit
     UnloadMe
  ELSEIF (hAnimation) THEN
    IF (hSwitch) THEN
       SendMessage(hAnimation, ACM_STOP, 0, 0)
       MySB.Panel(0).Caption = "Click to [>] PLAY animation"
    ELSE
       SendMessage(hAnimation, ACM_PLAY,-1,-1)
       MySB.Panel(0).Caption = "Click to [x] STOP animation"
    END IF
  END IF
END SUB

SUB UnloadMe
  IF (hAnimation) THEN SendMessage(hAnimation, ACM_STOP, 0,0)
  Me.Close
END SUB
