Date: 02-16-2022
Return to Index
created by gbSnippets
'The sndPlaySound function plays a *.wav sound file, but can also play one of the
'default sounds that comes with Windows, called with the following names.
'Some sound files are part of the Windows distribution and may be called
'using a system name. Here are a few of the familiar ones:
Default SystemStart
CriticalBatteryAlarm SystemNotification
MailBeep SystemExit
WindowsLogon SystemExclamation
WindowsLogoff SystemAsterisk
'Primay Code:
Dim iReturn As Long, SoundFile As Asciiz * %Max_Path
SoundFile = "sound.wav"
iReturn = sndPlaySound(SoundFile, %SND_ASYNC) 'play once, in background
iReturn = sndPlaySound(SoundFile, %SND_SYNC) 'play once, apps waits til song conpletes
iReturn = sndPlaySound(SoundFile, %SND_ASYNC Or %SND_LOOP) 'play continuously
iReturn = sndPlaySound("", %SND_ASYNC) 'stop once song has started
'For example, to play the mail sound, use this:
SoundFile = "MailBeep"
iReturn = sndPlaySound(SoundFile, %SND_ASYNC) 'play once, in background
'Note: sndPlaySound can also play WAV files. See this snippet: http://gbl_00208
'Compilable Example: (Jose Includes)
'press Start to play sound one time. Stop to cancel playing.
'this example actually plays 2 sounds - a file and a system sound
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
Global hDlg As DWord
Function PBMain() As Long
Dialog New Pixels, 0, "Test Code",300,300,200,200, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, 100,"Start", 50,10,100,20
Control Add Button, hDlg, 200,"Stop", 50,40,100,20
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Local iReturn as Long, SndFile as Asciiz * %Max_Path
If CB.Msg = %WM_Command AND CB.Ctl = 100 AND CB.Ctlmsg = %BN_Clicked Then
SndFile = "MailBeep"
iReturn = sndPlaySound(SndFile, %SND_SYNC) 'play sound once (in the background)
End If
If CB.Msg = %WM_Command AND CB.Ctl = 200 AND CB.Ctlmsg = %BN_Clicked Then
'stop sound once it has started
iReturn = sndPlaySound("", %SND_ASYNC)
End If
End Function
'gbs_00328
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm