Windows API Guide: OVERLAPPED Structure


Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long

Alternate Declare for when using a resource or memory location:
Declare Function PlaySound_Res Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As Long, ByVal hModule As Long, ByVal dwFlags As Long) As Long

Platforms: Win 32s, Win 95/98, Win NT

PlaySound plays a waveform sound through the speakers. This sound could be a .wav file, a system event sound (such as the system startup sound), or a sound resource stored in an application. Note that when the function needs to play an application resource or a RAM-loaded sound, Visual Basic users must use the alternate declare of the function in order to pass the numeric identifier of the sound instead of a string. The function returns 0 if an error occured, or a non-zero value if successful.

lpszName
The name or some other identifier of the sound. Its exact format depends on the flags passed as dwFlags.
hModule
A handle to the application module containing the sound resource the play, if needed. If the function does not need this information, pass 0 for this parameter.
dwFlags
Zero or more of the following flags specifying what lpszName refers to and how to play the sound:
SND_ALIAS = &H10000
lpszName is a string identifying the name of the system event sound to play.
SND_ALIAS_ID = &H110000
lpszName is a string identifying the name of the predefined sound identifier to play.
SND_APPLICATION = &H80
lpszName is a string identifying the application-specific event association sound to play.
SND_ASYNC = &H1
Play the sound asynchronously -- return immediately after beginning to play the sound and have it play in the background.
SND_FILENAME = &H20000
lpszName is a string identifying the filename of the .wav file to play.
SND_LOOP = &H8
Continue looping the sound until this function is called again ordering the looped playback to stop. SND_ASYNC must also be specified.
SND_MEMORY = &H4
lpszName is a numeric pointer refering to the memory address of the image of the waveform sound loaded into RAM.
SND_NODEFAULT = &H2
If the specified sound cannot be found, terminate the function with failure instead of playing the SystemDefault sound. If this flag is not specified, the SystemDefault sound will play if the specified sound cannot be located and the function will return with success.
SND_NOSTOP = &H10
If a sound is already playing, do not prematurely stop that sound from playing and instead return with failure. If this flag is not specified, the playing sound will be terminated and the sound specified by the function will play instead.
SND_NOWAIT = &H2000
If a sound is already playing, do not wait for the currently playing sound to stop and instead return with failure.
SND_PURGE = &H40
Stop playback of any waveform sound. lpszName must be an empty string.
SND_RESOURCE = &H4004
lpszName is the numeric resource identifier of the sound stored in an application. hModule must be specified as that application's module handle.
SND_SYNC = &H0
Play the sound synchronously -- do not return until the sound has finished playing.

Example:

' First play the SystemStart event sound synchronously.  Then loop ' playing the file C:\Sounds\scream.wav for 5 seconds before stopping. Dim retval As Long  ' return value of the function ' Synchronously play the SystemStart sound.  This function returns when the sound is done. retval = PlaySound("SystemStart", 0, SND_ALIAS Or SND_SYNC) ' Now loop the .wav file for five seconds before purging its playback.  Note that ' we don't want the default sound to play if the file is not found. retval = PlaySound("C:\Sounds\scream.wav", 0, SND_FILENAME Or SND_ASYNC Or SND_NODEFAULT Or SND_LOOP) Sleep 5000  ' wait for 5 seconds while sound loops retval = PlaySound("", 0, SND_PURGE Or SND_NODEFAULT)  ' stop playback 

See Also: sndPlaySound
Category: Audio

Go back to the alphabetical Function listing.
Go back to the Reference section index.


This page is copyright © 2000 Paul Kuliniewicz. Copyright Information.
Go back to the Windows API Guide home page.
E-mail: vbapi@vbapi.com Send Encrypted E-Mail
This page is at http://www.vbapi.com/ref/p/playsound.html



Windows API Guide
Windows API Guide - Reference - Volume 1: Version 3.0 For the MS-DOS and PC-DOS Operating Systems
ISBN: B001V0KQIY
EAN: N/A
Year: 1998
Pages: 610

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net