Private Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (lpszSoundName As Any, ByVal uFlags As Long) As Long
Private Declare Function sndStopSound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszNull As Long, ByVal uFlags As Long) As Long
Private Const SND_MEMORY = &H4
Private Const SND_SYNC = &H0
Private Const SND_ASYNC = &H1
Private Const SND_NODEFAULT = &H2
Private Const SND_LOOP = &H8
Private Const SND_NOSTOP = &H10Private arrBound()    As Byte
Private arrFired()    As Byte
Private arrNoBullet() As Byte
Private Function PlaySound(ind As Integer) As Boolean
    Dim r        As Long
    Dim uFlags   As Long
            
    uFlags = SND_ASYNC Or SND_NODEFAULT Or SND_MEMORY
    r = sndStopSound(0, SND_ASYNC)
    
    Select Case ind
        Case 0 'Fire
            r = sndPlaySound(arrFired(0), uFlags)
        Case 1 'Shotted
            r = sndPlaySound(arrBound(0), uFlags)
        Case 2 'esNoBullet
            r = sndPlaySound(arrNoBullet(0), uFlags)
    End Select
End FunctionPrivate Function LoadSound() As Boolean
    arrBound = LoadResData("Bound", "WAVE")
    arrFired = LoadResData("Fire", "WAVE")
    arrNoBullet = LoadResData("NoBullet", "WAVE")
End Function

解决方案 »

  1.   

    or by filename::
    sndPlaySound(filename, SND_ASYNC Or SND_NODEFAULT )
      

  2.   


    播放wav文件Private Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (lpszSoundName As Any, ByVal uFlags As Long) As Long
    Private Declare Function sndStopSound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszNull As Long, ByVal uFlags As Long) As Long
    Private Const SND_MEMORY = &H4
    Private Const SND_SYNC = &H0
    Private Const SND_ASYNC = &H1
    Private Const SND_NODEFAULT = &H2
    Private Const SND_LOOP = &H8
    Private Const SND_NOSTOP = &H10Private arrBound()    As Byte
    Private arrFired()    As Byte
    Private arrNoBullet() As Byte
    Private Function PlaySound(byval sFile as string) As Boolean
        Dim r        As Long
        Dim uFlags   As Long
                
        uFlags = SND_ASYNC Or SND_NODEFAULT Or SND_MEMORY
        r = sndStopSound(0, SND_ASYNC)
        r = sndPlaySound(sFile, uFlags)
        End Function第二个贴子是播放资源文件里的wav
      

  3.   

    更正
    播放wav文件Private Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (lpszSoundName As Any, ByVal uFlags As Long) As Long
    Private Declare Function sndStopSound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszNull As Long, ByVal uFlags As Long) As Long
    Private Const SND_MEMORY = &H4
    Private Const SND_SYNC = &H0
    Private Const SND_ASYNC = &H1
    Private Const SND_NODEFAULT = &H2
    Private Const SND_LOOP = &H8
    Private Const SND_NOSTOP = &H10Private Sub PlaySound(byval sFile as string) 
        Dim r        As Long
        Dim uFlags   As Long            
        uFlags = SND_ASYNC Or SND_NODEFAULT
        r = sndStopSound(0, SND_ASYNC)
        r = sndPlaySound(sFile, uFlags)
    End Sub
      

  4.   

    Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" 
    (ByVal lpszSoundName As String, ByVal uFlags As Long) As LongPublic Sub PlayWav(sFilename As String)X& = sndPlaySound(sFilename, 1)End Sub
      

  5.   

    Dim timecount As Long
    Private Sub Label1_Click()
        timecount = 60 * 8
     IeTimer1.Enabled = ValTrue
    End SubPrivate Sub IeTimer1_Timer()
        timecount = timecount - 1
       Label1.Caption = timecount \ 60 & "分" & timecount Mod 60 & "秒"
        If timecount = 60 Then
            Beep
        End If
        If timecount = 0 Then
            Beep
            IeTimer1.Enabled = False
        End If
    End Sub我想在上面的代码中用一个自己录的WAV文件代替Beep,怎么能实现呢?请指教,多谢!
      

  6.   


    Private Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (lpszSoundName As Any, ByVal uFlags As Long) As Long
    Private Declare Function sndStopSound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszNull As Long, ByVal uFlags As Long) As Long
    Private Const SND_MEMORY = &H4
    Private Const SND_SYNC = &H0
    Private Const SND_ASYNC = &H1
    Private Const SND_NODEFAULT = &H2
    Private Const SND_LOOP = &H8
    Private Const SND_NOSTOP = &H10private timecount As LongPrivate Sub Beep() 
        Dim r        As Long
        Dim uFlags   As Long,sFile as string                sFile=app.path & "\" & "x.wav" 'your own wave file name and place the wave file under your project directory    uFlags = SND_ASYNC Or SND_NODEFAULT
        r = sndStopSound(0, SND_ASYNC)
        r = sndPlaySound(sFile, uFlags)
    End Sub
    Private Sub Label1_Click()
        timecount = 60 * 8
     IeTimer1.Enabled = ValTrue
    End SubPrivate Sub IeTimer1_Timer()
        timecount = timecount - 1
       Label1.Caption = timecount \ 60 & "分" & timecount Mod 60 & "秒"
        If timecount = 60 Then
            Beep
        End If
        If timecount = 0 Then
            Beep
            IeTimer1.Enabled = False
        End If
    End Sub
      

  7.   

    我的声音文件放在了桌面上是1.wav
    像下面这样写对吗?
    借在哪里?sFile=app.path & "\" & "1.wav" 'your own wave file name and place the wave file under your project directory
      

  8.   

    你为什么要放到桌面上??
    放在你的工程目录里
    app.path是你当前工程的路径自己多动动手
      

  9.   

    可是POWERPOINT里面好像没有工程啊???????
      

  10.   

    我晕了,你自己看看帮助,app.path是什么意思总之sndPlaySound(sFile, uFlags)
    sFile是你存放的wave文件的路径文件名你自己把它的路径设置好了就可以了,可以不用app.path
      

  11.   

    sorry??you mean powerpoint??
      

  12.   

    我要在POWERPOINT里面实现倒计时的功能,只好借助里面的VB编辑器了,我不太会VB,多谢这里面的朋友帮我忙,说得这么详细,等忙完这个我一定要好好学学VB。谢谢!~