www.pudn.com > ownfirewall > Sound.bas
Attribute VB_Name = "Sound"
Option Explicit
Private Const CALLBACK_FUNCTION = &H30000
Private Const MM_WIM_DATA = &H3C0
Private Const WHDR_DONE = &H1 ' done bit
Private Const GMEM_FIXED = &H0 ' Global Memory Flag used by GlobalAlloc functin
Type WAVEHDR
lpData As Long
dwBufferLength As Long
dwBytesRecorded As Long
dwUser As Long
dwFlags As Long
dwLoops As Long
lpNext As Long
Reserved As Long
End Type
Type WAVEINCAPS
wMid As Integer
wPid As Integer
vDriverVersion As Long
szPname As String * 32
dwFormats As Long
wChannels As Integer
End Type
Type WAVEFORMAT
wFormatTag As Integer
nChannels As Integer
nSamplesPerSec As Long
nAvgBytesPerSec As Long
nBlockAlign As Integer
wBitsPerSample As Integer
cbSize As Integer
End Type
Public Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
Private Declare Function waveInOpen Lib "winmm.dll" (lphWaveIn As Long, ByVal uDeviceID As Long, lpFormat As WAVEFORMAT, ByVal dwCallback As Long, ByVal dwInstance As Long, ByVal dwFlags As Long) As Long
Private Declare Function waveInPrepareHeader Lib "winmm.dll" (ByVal hWaveIn As Long, lpWaveInHdr As WAVEHDR, ByVal uSize As Long) As Long
Private Declare Function waveInReset Lib "winmm.dll" (ByVal hWaveIn As Long) As Long
Private Declare Function waveInStart Lib "winmm.dll" (ByVal hWaveIn As Long) As Long
Private Declare Function waveInStop Lib "winmm.dll" (ByVal hWaveIn As Long) As Long
Private Declare Function waveInUnprepareHeader Lib "winmm.dll" (ByVal hWaveIn As Long, lpWaveInHdr As WAVEHDR, ByVal uSize As Long) As Long
Private Declare Function waveInClose Lib "winmm.dll" (ByVal hWaveIn As Long) As Long
Private Declare Function waveInGetDevCaps Lib "winmm.dll" Alias "waveInGetDevCapsA" (ByVal uDeviceID As Long, lpCaps As WAVEINCAPS, ByVal uSize As Long) As Long
Private Declare Function waveInGetNumDevs Lib "winmm.dll" () As Long
Private Declare Function waveInGetErrorText Lib "winmm.dll" Alias "waveInGetErrorTextA" (ByVal err As Long, ByVal lpText As String, ByVal uSize As Long) As Long
Private Declare Function waveInAddBuffer Lib "winmm.dll" (ByVal hWaveIn As Long, lpWaveInHdr As WAVEHDR, ByVal uSize As Long) As Long
'constants
Public Enum sndConst
SND_ASYNC = &H1 ' play asynchronously
SND_LOOP = &H8 ' loop the sound until Next sndPlaySound
SND_MEMORY = &H4 ' lpszSoundName points To a memory file
SND_NODEFAULT = &H2 ' silence Not default, If sound not found
SND_NOSTOP = &H10 ' don't stop any currently playing sound
SND_SYNC = &H0 ' play synchronously (default), halts prog use till done playing
End Enum
Public PortCloseWv As String
Public PortOpenWv As String
Public ConnectionWv As String
Public Function PlayWav(strPath As String, sndVal As sndConst)
Dim Rtn As Long
Rtn = sndPlaySound(strPath, sndVal)
End Function
Public Sub Command1()
PlayWav App.Path & "\" & ConnectionWv, SND_ASYNC 'you can use many other constants too
End Sub
Public Sub Command2()
PlayWav App.Path & "\" & PortOpenWv, SND_ASYNC 'you can use many other constants too
End Sub
Public Sub Command3()
PlayWav App.Path & "\" & PortCloseWv, SND_ASYNC 'you can use many other constants too
End Sub