This document is designed as part of a series of demo script documents to
assist customers who are evaluating Microsoft® Visual FoxPro™ 5.0. It can
be used by an individual developer learning a new feature in Visual FoxPro
5.0; or as the basis for a demo shown to other developers and software tools
evaluators. This demo script requires Visual FoxPro 5.0 to be installed.
Questions about this demo script should be directed via email to
foxmktg@microsoft.com.
Introduction
ActiveX™ controls (formerly known as OLE controls) are reusable software
components that can be added to existing applications with minimal additional
coding. Using ActiveX controls, developers can add unique functionality to
their applications using prebuilt and pretested components. With over 2,000
ActiveX controls currently available, Visual FoxPro developers can access a
rich inventory of components to extend and enhance their applications.
Developers can use the tools in Microsoft Visual Studio 97™ or Visual
Basic® Control Creation Edition to create their own redistributable
ActiveX controls.
One of the key enhancement areas for Visual FoxPro 5.0 is improved support for
ActiveX controls. With Visual FoxPro 5.0, developers can choose from a wider
variety of ActiveX controls, and can also modify a control's behavior through
Visual FoxPro classes. (This capability is demonstrated in the document
entitled, "Demo Script: Subclassing ActiveX Controls in Visual FoxPro 5.0,"
available from the same location as this document.)
ActiveMovie™ is an extensible media streaming architecture for Microsoft®
Windows® that delivers high quality audio and video playback from the
Internet or Intranet. ActiveMovie supports the most popular media types, including MPEG
audio and video, AVI video, WAV audio, and Apple® QuickTime® video.
-
The ActiveMovie ActiveX control is a custom control that you can use with
Visual FoxPro to quickly add support for multimedia streams to your
applications. The purpose of this document is to illustrate the power and
simplicity of working with ActiveX controls in Visual FoxPro. The ActiveMovie
control is used because it is visually interesting, and because it is a good
generic example of an ActiveX control.
-
Note: The ActiveMovie control can be downloaded from Microsoft's Web
site at www.microsoft.com/msdownload/ieplatform/iewin95.htm. Full
documentation on ActiveMovie can be found at www.microsoft.com/developer/tech/amov1doc/
.
Add Controls to a Form
Create a new form by typing create form in the Command window. Set the
properties of the form as follows:
Property
|
Value
|
AutoCenter
|
.T.
|
Caption
|
Movie Player Form
|
Height
|
350
|
Width
|
575
|
Note: The form height and width have been selected to create a form big
enough to hold a representative sample of movies. If your movies are larger or
smaller you may want to adjust the form size.
Choose New Property from the Form menu to add two custom
properties to the form. In the New Property dialog enter cMoviePath as
the first property name. Choose Add and then enter cMovieFiles
as the second property name. Choose Close to return to the form.
Custom properties are a powerful feature in Visual FoxPro. Custom properties
enable the developer to easily customize objects in Visual FoxPro. Custom
properties are to objects what fields are to database tables – they store
attributes of an object in a known, named, and callable location.
The cMoviePath custom property stores the folder location for your
movies. Code will be added later to populate a list box with the available
movies. In the Properties window set the cMoviePath property of the
form to the directory that contains the movies. For instance, if all of your
movies are stored in the C:\Movies directory you would set the cMoviePath
property to c:\movies.
The cMovieFiles property allows you to limit the movies that appear in
the list box to those that meet a criteria. For instance, if you wanted only
your X-Files movies to appear in the list you might set the property to xf*.*.
Click on the OLE Container Control button on the Form Controls toolbar.
Position the mouse cursor anywhere on the form and then drag until you have a
rectangle. In the Insert Object dialog choose Insert Control.
The Control Type list then shows all of the ActiveX controls registered on
your machine. Choose ActiveMovie Control Object from the list
and then choose OK. Set the properties of the control as follows:
Property
|
Value
|
Height
|
192
|
Left
|
240
|
Name
|
ocxMovie
|
Top
|
12
|
Visible
|
.F.
|
Width
|
450
|
Add a list box to the form to allow the user to select a movie for viewing.
Set the properties of the list box as follows:
Property
|
Value
|
Height
|
222
|
Left
|
12
|
Name
|
lstMovies
|
Top
|
30
|
Value
|
""
|
Width
|
204
|
Add a label to the form to instruct the user to select a movie. Set the
properties of the label as follows:
Property
|
Value
|
Caption
|
Choose a movie:
|
Height
|
18
|
Left
|
12
|
Top
|
12
|
Width
|
115
|
Add two command buttons that will be used to run, pause, and stop the movie.
Set the properties of the command buttons as follows:
Property
|
Value
|
Value
|
Caption
|
Run
|
Stop
|
Enabled
|
.F.
|
.F.
|
Height
|
25
|
25
|
Left
|
12
|
96
|
Name
|
cmdRun
|
cmdStop
|
Top
|
264
|
264
|
Width
|
54
|
54
|
Add a check box to the form to allow the user to run the movie in twice its
original size. Set the properties of the check box as follows:
Property
|
Value
|
Caption
|
Double Size
|
Height
|
17
|
Left
|
12
|
Name
|
chkDoubleSize
|
Top
|
306
|
Width
|
109
|
Add Code to the Form and Controls
You are now ready to add code to the form and its controls to load the
selected movie, and then resize, run, pause, and stop the movie.
Add the following code to the Init method of the form. This code will
be run automatically when the form is started. The code creates an array that
contains all of the movies that are available to be viewed, based on the
setting of the form's cMoviePath and cMovieFiles properties. The
code then populates the form's list box with the files.
* Create an array with a list of all movies that
* can be viewed.
nFile = ADir(aMovies, ThisForm.cMoviePath + ;
"\" + ThisForm.cMovieFiles)
* If there are any, then populate the list box with
* their file names.
IFIf nFile > 0
for i=1 to nfile
ThisForm.lstMovies.AddItem(aMovies[i,1])
NEXT
ENDIF
Add the following code to the InteractiveChange method of the list box.
This code will be run every time the user selects a movie from the list.
ActiveX controls are programmed via their properties and methods, just like
Visual FoxPro objects. The code sets the FileName property of the
ActiveMovie control, which loads the movie so it can be played. The ShowControls
property of the control is set to hide the built-in controls for running,
pausing, stopping, etc. These controls are not needed because there are Visual
FoxPro command buttons on the form to do this.
* Set properties of the ActiveMovie control.
WITH ThisForm.ocxMovie
* What movie is to be viewed?
.Filename = ThisForm.cMoviePath + "\" + This.Value
* Don't show the user interface elements of the control.
.ShowControls = .F.
* Don't show the status display panel.
.ShowDisplay = .F.
* Make the control visible.
.Visible = .T.
ENDWITH
* Enable the Run button and make sure its caption says Run.
ThisForm.cmdRun.Enabled = .T.
ThisForm.cmdRun.Caption = "Run"
Add the following code to the Click method of the Run button. This code
runs or pauses the movie and then changes the caption of the command button
from Run to Pause or vice versa.
IF This.Caption = "Run"
* If the caption says Run.
ThisForm.cmdStop.Enabled = .T.
* Change the caption to Pause.
This.Caption = "Pause"
* Run the movie.
ThisForm.ocxMovie.Run
ELSE
* If the caption says Pause.
* Change the caption to Run.
This.Caption = "Run"
* Pause the movie.
ThisForm.ocxMovie.Pause
ENDIF
Put the following code in the Click method of the Stop button. This
code stops the movie and set the caption of the Run button to Run so
the movie can be replayed.
This.Enabled = .F.
ThisForm.cmdRun.Enabled = .T.
* Change the caption to Run.
ThisForm.cmdRun.Caption = "Run"
* Stop the movie.
ThisForm.ocxMovie.Stop
Add the following code to the InteractiveChange method of the check
box. This code will be run every time the user changes the state of the check
box. The code switches the movie size to either its original size or to double
its original size.
* Change the size of the movie to either its original
* size (0) or to double its original size (1).
ThisForm.ocxMovie.MovieWindowSize = This.Value
Finally, add the following code to the StateChange method of the
ActiveMovie control. This code is run when there is a change in the state of
the multimedia source. In this form we want to know when the movie is finished
running so the Stop button can be disabled and the Run button's caption can be
set back to Run.
LPARAMETERS oldstate, newstate
IF oldstate = 2 And newstate = 0
* The movie has finished running.
ThisForm.cmdRun.Caption = "Run"
ThisForm.cmdStop.Enabled = .F.
ENDIF
The variable oldstate represents the state the movie was in before it
changed. The variable newstate represents the new state of the movie.
When the movie is finished the state changes from 2 to 0 and the code above
runs.
Save and run the form. The list box will contain a list of movie files that
meet the conditions determined by the form's cMoviePath and cMovieFiles
properties. When you select a movie it is loaded by the ActiveMovie control.
You can then see a black box on the screen where the movie will run. Use the
check box to change the size of the movie. Choose Run to start the
movie, Pause to pause the movie, and Stop to end the movie. You
can rerun the movie by choosing Run or you can select a different movie
from the list.
More Things to Try
There are many more properties of the ActiveMovie control than are used in
this demo. The following table lists additional properties that you can set in
order to change the way the demo works.
For instance, you might add a spinner to the form to change the Volume
or PlayCount properties. You might use check boxes to set the AutoRewind
and AutoStart properties.
Property
|
Description
|
AutoRewind
|
Indicates whether to automatically rewind the multimedia stream when it stops.
|
AutoStart
|
Indicates whether to automatically start playing the multimedia stream.
|
Balance
|
Specifies the stereo balance.
|
DisplayMode
|
Indicates whether the control displays the current position in time or frames.
|
Duration
|
Specifies the duration of the multimedia stream in seconds.
|
EnableContextMenu
|
Indicates whether to enable the context menu on right click.
|
EnablePositionControls
|
Indicates whether to enable the position buttons in the control panel.
|
EnableSelectionControls
|
Indicates whether to enable the selection buttons in the control panel.
|
EnableTracker
|
Indicates whether to enable the tracker bar in the control panel.
|
FullScreenMode
|
Expands the area of the OCX so that it fills the entire screen.
|
PlayCount
|
Specifies the number of times to play this multimedia stream.
|
ShowPositionControls
|
Indicates whether the position buttons are visible in the control panel.
|
ShowSelectionControls
|
Indicates whether the selection buttons are visible in the control panel.
|
ShowTracker
|
Indicates whether the tracker bar is visible in the control panel.
|
Volume
|
Specifies the audio volume.
|
In addition, you might want to replace the list box with the common dialog
control and let the user specify the directory and the file extensions. That
way you wouldn't have to hard code the movies directory and you could also
display in the list more than one file type at a time.
Summary
ActiveX controls are a powerful way of reusing components to speed application
development and simplify maintenance. ActiveX controls enable Visual FoxPro
developers to quickly add unique functionality to their applications, and to
share that functionality among several development and runtime environments.
Visual FoxPro 5.0 has enhanced support for ActiveX controls, making available
a wider range of controls for the Visual FoxPro developer. The programming
model for ActiveX controls is simple and straightforward, and similar in many
respects to Visual FoxPro native objects.
Frequently-Asked Questions
How can I learn more about using ActiveX controls with Visual FoxPro 5.0?
A good place to start is the white paper entitled, "ActiveX Controls and
Visual FoxPro 5.0," found on the Visual FoxPro Web site. Also, see Chapter 16,
"Adding OLE," in the Developer's Guide, part of the documentation
that came with your copy of Visual FoxPro 5.0.
Can Visual FoxPro 5.0 create ActiveX controls?
Visual FoxPro is an application development environment that focuses on
assembling applications from components, rather than on building components
per se. Microsoft provides several tools for component creation (Visual
C++®, Visual Basic®, Visual Basic - Control Creation Edition, Visual
J++™).
What other products can use ActiveX controls?
All of the tools in Visual Studio 97™, plus Microsoft® Office 97 and
Microsoft® Internet Explorer. ActiveX controls are a standard component of
Windows, so many other third-party products support them as well.
How are a control's properties and methods documented?
In many cases, controls install with help files (.HLP) which describe how to
program them. In cases where no help files are included, developers can use an
Object Browser which ships with several other Microsoft tools, to inspect the
control's properties, events, and methods.
Can I obtain an evaluation copy of Visual FoxPro 5.0?
Visual FoxPro 5.0, and all Microsoft products, are available with a 30-day
money back guarantee from software resellers. Therefore, if you purchase the
product on a trial basis, and decide not to keep it, simply return it for a
full refund.
How do I get the Visual Basic Control Creation Edition (VBCCE)?
Visual Basic - Control Creation Edition is free, available for download.
Please see www.microsoft.com/vbasic/ for more information.