Date: 02-16-2022
Return to Index
created by gbSnippets
'The sndPlaySound function plays a *.wav sound file, but can also play a
'wave file embedded within a resource file.
'Primay Code:
Dim iReturn As Long, SoundFile As Asciiz * %Max_Path
SoundFile = "resourceID"
iReturn = sndPlaySound(SoundFile, %SND_ASYNC Or %SND_RESOURCE) 'play once, in background
iReturn = sndPlaySound(SoundFile, %SND_SYNC Or %SND_RESOURCE) 'play once, apps waits til song conpletes
iReturn = sndPlaySound(SoundFile, %SND_ASYNC Or %SND_LOOP Or %SND_RESOURCE) 'play continuously
iReturn = sndPlaySound("", %SND_ASYNC Or %SND_RESOURCE) 'stop once song has started
'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 the gbsnippets.wav file that is found
'in the gbsnippets.pbr, under the ID "alarm"
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
#Resource "gbsnippets.pbr"
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 = "alarm"
iReturn = sndPlaySound(SndFile, %SND_SYNC Or %SND_RESOURCE) '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 Or %SND_RESOURCE)
End If
End Function
'gbs_00350
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm