1. Using set bell to
The format of the set bell to command of VFP5.0 is different from the format of FoxPro2.X. In VFP5.0, its format is Set Bell To [cWAVFileName, nDuration]. Among them, cWAVFileName is a .WAV file; nDuration is the duration (note that this item cannot be omitted, otherwise a syntax error will occur). So that when you use set bell to in the initial module of your personal program to direct to a .WAV file, you can use it in subsequent modules? chr(7) to play the .WAV file.
Example 1:
set bell on && to enable bell
set bell to′ .WAV file′,0 && to direct bell to a .WAV file . Note the single quotes
?chr(7)
&&Play the .WAV file
2. Create using OLE container control
Create a form, click the "OLE Container Control" button in the form control toolbar, and then click or drag at the appropriate location on the form. In the "Insert Object" window that appears, select "Creat New" or "Creat From File", use the "Browse" button to select your own .WAV file, and confirm.
A "speaker" icon will appear in the current form. Set the attribute "AutoActivate" of the icon to 1 to automatically play the .WAV file whenever the form is run to achieve background music; set the Height When , and Width are both 0, the "speaker" icon can be hidden.
3. Use VFP library Foxtools.fll
Use =Regfn() and =Callfn() to access the audio module in Foxtools.fll to play sound files.
Example 2:
Create a form and enter the following code in its Activate event:
public ss &&define a global variable ss
< p> set library to foxtools.fll &&Open library Foxtools.fllss=Regfn(〃SndPlaySound〃,〃CI〃,〃I〃,〃mmsystem〃) &&Get audio information
< p> =Callfn(ss,〃一.wav file〃,n) &&n=0 (1,2,3 is also acceptable), it will only play once, and n=9, it will play in a loopIn its Destroy event Enter the following code in:
=Callfn(ss,〃〃,10) &&stop playing
set library to &&release the library foxtools.fll from memory
4. Using the Windows dynamic link library
In the VFP5.0 installation directory samplesclasses, there is a class library samplesclasses. There are two types of controls provided: video and audio. Audio can control .WAV and .MID files, which can be used to easily implement background music. An example of it is given below.
Example 3:
Create a form, select the class button in the form control toolbar, and add the samplesclassessamples.vbx class library in VFP5.0. At this time, two multimedia controls, SoundPlayer and VideoFrame, will appear in the form control toolbar. Select SoundPlayer, click on the form, and set its properties as follows:
AutoOpen=.t.
AutoPlay=.t.
AutoRepeat=. t.
Class=SoundPlayer
Soundfile=Specify a .WAV or .MID file&¬e that there are no quotation marks
Visible=.f. &&Invisible
p>Each of the above methods has its own advantages and disadvantages, and you should pay attention to meeting your own programming needs when applying them.