如何播放影片

出自VFP Wiki

跳轉到: 導航, 搜尋

如何播放影片

出處:Calvin Hsia's WebLog : Play movies with an ActiveX control

摘錄程式碼如下(The following code is cliped from the above article):

PUBLIC ox as MyForm
ox=CREATEOBJECT("MyForm")
*Regsvr32 c:\WINDOWS\system32\msdxm.ocx
DEFINE CLASS MyForm as Form
          height=900
          width = 1124
          oEv=0 && Event handler ref
          allowoutput=.f.
          fLoaded=.f.

          ADD OBJECT oc AS OleControl with;
                   oleclass="AMOVIE.ActiveMovieControl.2"

          PROCEDURE init
                   cFilename="d:\slides.avi"
                   this.oc.width=thisform.Width
                   this.oc.height= thisform.Height
                   this.oc.filename=cFilename
                   this.oEv = CREATEOBJECT("evHandler",this)
                   EVENTHANDLER(this.oc.object,this.oEv)
                   IF thisform.Left < 0 or thisform.Left > SYSMETRIC(1)-100        && on 2nd monitor
                             thisform.oc.object.MovieWindowSize= 1
                   ELSE
                             thisform.oc.object.MovieWindowSize= 4  && amvOneHalfScreen
                   ENDIF
                   this.Show

                   DO WHILE !thisform.fLoaded
*!*                         DO WHILE this.oc.object.currentstate = -1
                             IF INKEY(.5)=27
                                      EXIT
                             ENDIF
                   ENDDO
                   thisform.oc.object.run
ENDDEFINE

DEFINE CLASS evHandler AS custom
          IMPLEMENTS DActiveMovieEvents2 IN "C:\WINDOWS\SYSTEM32\AMCOMPAT.TLB"
          oForm=null

          PROCEDURE init(oForm)
                   this.oForm=oForm

          PROCEDURE DActiveMovieEvents2_StateChange(oldState AS Number, newState AS Number) AS VOID;
                                      HELPSTRING "Indicates that the current state of the movie has changed"
          * add user code here
          ENDPROC

          PROCEDURE DActiveMovieEvents2_PositionChange(oldPosition AS Number, newPosition AS Number) AS VOID;
                                      HELPSTRING "Indicates that the current position of the movie has changed"
          * add user code here
          ENDPROC

          PROCEDURE DActiveMovieEvents2_Timer() AS VOID;
                                      HELPSTRING "ActiveMovie Control's progress timer"
          * add user code here
          ENDPROC

          PROCEDURE DActiveMovieEvents2_OpenComplete() AS VOID;
                                      HELPSTRING "Reports that an asynchronous operation to open a file has completed successfully"
                   ?PROGRAM()
                   this.oform.fLoaded=.t.
          ENDPROC

          PROCEDURE DActiveMovieEvents2_Click() AS VOID
          * add user code here
          ENDPROC

          PROCEDURE DActiveMovieEvents2_DblClick() AS VOID
          * add user code here
          ENDPROC

          PROCEDURE DActiveMovieEvents2_KeyDown(KeyCode AS INTEGER, Shift AS INTEGER) AS VOID
          * add user code here
          ENDPROC

          PROCEDURE DActiveMovieEvents2_KeyUp(KeyCode AS INTEGER, Shift AS INTEGER) AS VOID
          * add user code here
          ENDPROC

          PROCEDURE DActiveMovieEvents2_KeyPress(KeyAscii AS INTEGER) AS VOID
          * add user code here
          ENDPROC

          PROCEDURE DActiveMovieEvents2_MouseDown(Button AS INTEGER, Shift AS INTEGER, x AS Number, y AS Number) AS VOID
          * add user code here
          ENDPROC

          PROCEDURE DActiveMovieEvents2_MouseMove(Button AS INTEGER, Shift AS INTEGER, x AS Number, y AS Number) AS VOID
          * add user code here
          ENDPROC

          PROCEDURE DActiveMovieEvents2_MouseUp(Button AS INTEGER, Shift AS INTEGER, x AS Number, y AS Number) AS VOID
          * add user code here
          ENDPROC

          PROCEDURE DActiveMovieEvents2_Error(SCode AS INTEGER, Description AS STRING, Source AS STRING, CancelDisplay AS LOGICAL) AS VOID
          * add user code here
          ENDPROC

          PROCEDURE DActiveMovieEvents2_DisplayModeChange() AS VOID;
                                      HELPSTRING "Indicates that the display mode of the movie has changed"
          * add user code here
          ENDPROC

          PROCEDURE DActiveMovieEvents2_ReadyStateChange(ReadyState AS VARIANT) AS VOID;
                                      HELPSTRING "Reports that the ReadyState property of the ActiveMovie Control has changed"
          * add user code here
          ENDPROC

          PROCEDURE DActiveMovieEvents2_ScriptCommand(bstrType AS STRING, bstrText AS STRING) AS VOID
          * add user code here
          ENDPROC

ENDDEFINE