在VB中用API实现多媒体
′播放CD和AVI所需要的声明。
Declare Function mciSendString Lib ″MMSYSTEM″(ByVal lpstrCommand as String,ByVal lpstrReturnStr as Any,By Val wRetumLen as Integer,ByVal hCallBack as Integer) as Long
′播放WAV所需要的声明
Declare Function sndPlaySound Lib ″MMSYSTEM.DLL″(ByVal lpszSoundName as String,ByVal wF1ags as Integer) as Integer
′检测声卡所需要的声明
Declare Function auxGetNaumDevs Lib ″MMSYSTEM″()as Integer
′所用到的全局变量声明
Global Const SND_SYNC=&H0000 ′播放WAV用到的全局变量
Global Const SND_ASYNC=&-H0001 ′播放WAV用到的全局变量
Global Const SND_NODEFAULT=&H0002 ′播放WAV用到的全局变量
Global Const SND_LOOP=&H0008 ′播放WAV用到的全局变量
Global Const SND_NOSTOP=&-H0010 ′播放WAV用到的全局变量
′接下来是调用这些声明
Function auxTest()as Boolean
Dim i As Integer
i=auxGetNumDevs()
If i>0 Then
AuxTest=True ′如果有声卡则返回真
Exit Function
Else
AuxTest=False ′如果未检测到声卡则返回假
Exit Function
Else
AuxTest=False ′如果未检测到声卡则返回假
Exit Function
End If
End Function
2.播放CD的源代码
Sub PlayCD(b As Integer)
′ b为所播的音轨号
Dim a As Long
a=mciSendString(″open cdaudio alias cd wait″,0&,0,0) '初始化驱动
a=mciSendString(″set cd time format tmsf″,0&,0,0)
a=mciSendString(″play cd from″& Str(b),0&,00) ′播放音轨
End Sub
3.播放AVI的源代码
Sub playAVI(AVIFile As String)
Dim RVal as Long
AVIFile=″play″+AVIFile+″fullscreen″ ′全屏幕播放AVI文件
RVal=mciSendString(AVIFile,0&,0,0&)
End Sub
4.播放WAV的源代码
Sub playWAV(WAVFile As String)
Dim Flag as Integer
Dim a as Integer
wFlag=SND_ASYNC or SND_NODEFAULT
a=sndPlaySound(WAVFile,Flag)
End Sub
以上程序是我在调用多媒体时所常用的模块,你只需将上面的模块在程序中直接调用即可。