GFPlayWaveFile/GFPlayWaveFile.frm
VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 3195
ClientLeft = 60
ClientTop = 345
ClientWidth = 4710
LinkTopic = "Form1"
ScaleHeight = 3195
ScaleWidth = 4710
StartUpPosition = 3 'Windows‑Standard
Begin VB.CommandButton Command2
Caption = "Play"
Height = 315
Left = 2580
TabIndex = 0
Top = 2760
Width = 1995
End
Begin VB.CommandButton Command1
Caption = "Silence"
Height = 315
Left = 480
TabIndex = 1
Top = 2760
Width = 1995
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
'(c)2001, 2004 by Louis. Use to easily play any (small) wave file.
'
'Downloaded from www.louis‑coder.com.
'An easy way to play any small wave file.
'
'GFPlayWaveFile
Private Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
'GFPlayWaveFile
Private Const SND_SYNC = &H0 'play synchronously (default)
Private Const SND_ASYNC = &H1 'play asynchronously
Private Const SND_NODEFAULT = &H2 'silence not default, if sound not found
'GFPlayWaveFile
Private Const SND_ABORT As String = "" 'self‑made
Private Const SND_SILENCE As String = SND_ABORT 'self‑made
Private Sub Command1_Click()
'on error resume next
Call GFPlayWaveFile(SND_ABORT)
End Sub
Private Sub Command2_Click()
'on error resume next
Dim ProgramPath As String
'begin
ProgramPath = App.Path
If Not (Right$(ProgramPath, 1) = "\") Then ProgramPath = ProgramPath + "\" 'verify
Call GFPlayWaveFile(ProgramPath + "LoudSquish.wav")
End Sub
Private Sub GFPlayWaveFile(ByVal WaveName As String)
On Error GoTo Error: 'if sound system not available
'
'NOTE: if playing an old wave file is not finished yet, another call of this
'sub will abort playing old file (use GFPlayWaveFile("") to abort playing).
'
If Not ((Dir(WaveName) = "") Or (Right$(WaveName, 1) = "\") Or (WaveName = "")) Then 'verify
Call sndPlaySound(WaveName, SND_ASYNC)
Else
If WaveName = "" Then
'abort playing a wave file
Call sndPlaySound("", SND_ASYNC Or SND_NODEFAULT)
Else
'error
MsgBox "internal error in GFPlayWaveFile(): file '" + Left$(WaveName, 512) + "' not found !", vbOKOnly + vbExclamation
End If
End If
Exit Sub
Error:
MsgBox "internal error in GFPlayWaveFile() !", vbOKOnly + vbExclamation
Exit Sub
End Sub
[END OF FILE]