Other than the standard BEEP is it possible to generate any other sounds and if so how?
Printable View
Other than the standard BEEP is it possible to generate any other sounds and if so how?
VB Code:
Option Explicit Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long Private Const SND_APPLICATION = &H80 ' look for application specific association Private Const SND_ALIAS = &H10000 ' name is a WIN.INI [sounds] entry Private Const SND_ALIAS_ID = &H110000 ' name is a WIN.INI [sounds] entry identifier Private Const SND_ASYNC = &H1 ' play asynchronously Private Const SND_FILENAME = &H20000 ' name is a file name Private Const SND_LOOP = &H8 ' loop the sound until next sndPlaySound Private Const SND_MEMORY = &H4 ' lpszSoundName points to a memory file Private Const SND_NODEFAULT = &H2 ' silence not default, if sound not found Private Const SND_NOSTOP = &H10 ' don't stop any currently playing sound Private Const SND_NOWAIT = &H2000 ' don't wait if the driver is busy Private Const SND_PURGE = &H40 ' purge non-static events for task Private Const SND_RESOURCE = &H40004 ' name is a resource name or atom Private Const SND_SYNC = &H0 ' play synchronously (default)
Usage:
'This will play a sound located in your apps path
Private Sub Command1_Click()
PlaySound App.Path & "\clap.wav", 0&, SND_ASYNC Or SND_NODEFAULT
End Sub
Stop playing Wav:
PlaySound "C:\welcome.wav", 0&, &H4
I think redwing was referring to VBs ability to generate a sound, like QB's Sound statement.
If you are using NT, you can use the Beep API, which will let you specify the frequency and the duration. However in Win95/98 you cannot, the parameters that you pass will be ignored.
VB Code:
Declare Function Beep Lib "kernel32" Alias "Beep" (ByVal dwFreq As Long, ByVal dwDuration As Long) As Long
I posted some code for a DLL to do this somewhere a while ago - it's basically a replacement for Beep that actually takes into account the parameters. Note that you shouldn't use it on NT ;)