Partager via


Play movies with an ActiveX control

I’ve been using Canon Powershot cameras for years, and they take movies in AVI format as well as being a good camera.

I store my photos and movies in the same folders, and use the same database to store them.

To display the movies, I add a Windows Media Player ActiveX control. There have been various versions of Media Player over the years, with varying architectures. You may have to Regsvr32 c:\WINDOWS\system32\msdxm.ocx

For some reason, the events didn’t quite work right on one of my machines. Simple solution: I found the events code in c:\windows\system32\amcompat.tlb, and I started the VFP Object Browser, navigated to this file, then dragged the interface DActiveMovieEvents2 into a program file to have the IMPLEMENTS code auto-generated.

Sample code in Fox and VB is below.

For the VB version, you need to right click on the Toolbox, Choose Items…, then check the COM ActiveMovieControl Object (Microsoft ActiveMovie Control).

See also

Sharing Disneyland Digital pictures,

Various ways to display multiple photographs,

Using ActiveX Controls with Windows Forms in Visual Studio .NET

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

VB.Net sample here:

Public Class Form1

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Me.Height = 900

        Me.Width = 1124

        Me.AxActiveMovie1.MovieWindowSize = AMovie.WindowSizeConstants.amvDoubleOriginalSize

        Me.AxActiveMovie1.FileName = "d:\slides.avi"

    End Sub

    Private Sub AxActiveMovie1_OpenComplete(ByVal sender As Object, ByVal e As System.EventArgs) Handles AxActiveMovie1.OpenComplete

        Me.AxActiveMovie1.Run()

    End Sub

End Class

Comments

  • Anonymous
    May 31, 2010
    Thank you so much