Playing Sounds Specified in the Registry

The PlaySound function will also play sounds referred to by a keyname in the registry. This allows users to assign their own sounds to system alerts and warnings, or to user actions, such as a mouse button click. Sounds that are associated with system alerts and warnings are called sound events.

To play a sound event, call PlaySound with the pszSound parameter pointing to a string containing the name of the registry entry that identifies the sound. For example, to play the sound associated with the "MouseClick" entry and to wait for the sound to complete before returning, use the following statement:

PlaySound("MouseClick", NULL, SND_SYNC);

If the specified registry entry or the waveform-audio file it identifies does not exist, or if the file does not fit into the available memory, PlaySound plays the default system sound.

The sound events that are predefined by the system can vary with the platform. The following list gives the sound events that are defined for all implementations of the Win32 API:


If an application registers its own sound events, the user can configure the sound event by using the standard Control Panel interface. The application should register the sound event by using the standard registry functions; for more information, see Registry. The entries belong at the same position in the registry hierarchy as the rest of the sound events. This position varies with the Win32 implementation. The appropriate data value also varies with the implementation.

The sndPlaySound function always searches the registry for a keyname matching lpszSound before attempting to load a file with this name. The PlaySound function accepts flags that specify the location of the sound.

Software for developers
Delphi Components
.Net Components
Software for Android Developers
More information resources
Unix Manual Pages
Delphi Examples