mccad 发表于 2005-4-21 21:40:00

让你的VBA或VB程序也能播音乐

'播放器调用
Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long
Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
Public Const SND_SYNC = &H0
Public Const SND_ASYNC = &H1
Public Const SND_LOOP = &H8' 播放MID文件
Public Sub PlayMID(strFileName As String)
       Dim lngRet As Long
       lngRet = mciSendString("open " & strFileName & " type sequencer alias canyon", 0&, 0, 0)
       lngRet = mciSendString("play canyon wait", 0&, 0, 0)
       lngRet = mciSendString("close canyon", 0&, 0, 0)
End Sub' 播放WAV文件
Public Sub PlayWav(strFileName As String , ChkRepeat As Boolean)
       Dim intRetval As Integer
       intRetval = sndPlaySound(ByVal strFileName,   IIf(chkRepeat, SND_ASYNC Or SND_LOOP, SND_ASYNC))
       'If intRetval = 0 Then MsgBox ("Error!")
End Sub

小美菜 发表于 2005-4-21 22:01:00

老大,放音乐时可否干工作(如再CAD的VBA其它程序运行)?

mccad 发表于 2005-4-21 22:17:00

它只管放,音乐放后程序也就不对音乐进行控制了,程序在启动了音乐后就会继续运行后续的程序内容。

小美菜 发表于 2005-4-22 21:31:00

今天我试过,MID格式可否循环播放?放完后进程是否自动终止?好像不是必须关掉后才能进行下一支歌曲的播放!!

tqmark 发表于 2005-4-23 21:08:00

thank you !好东西,以后老大多发点程序哈,再次感谢
页: [1]
查看完整版本: 让你的VBA或VB程序也能播音乐