66 Votes

Delphi: Play System-Sounds

Tutorial by Delphian | 2012-06-29 at 15:33

Delphi makes it very easy to play system sounds like the start-up tone, the end-sound or the standard error sound within your own application.

We are using the PlaySound function from the unit MMSystem for this, with which it is possible to play any wave file. We can pass to PlaySound a file or the name of a system sound as well as information about how the sound should be played:

uses MMSystem;

The example plays the Windows start-up tone (constant SYSTEMSTART) for a single time (SND_ASYNC).

Constants for System Sounds

Instead of "SYSTEMSTART" we can use the following other constants with PlaySound:

  • SYSTEMHAND (Critical Stop)
  • SYSTEMSTART (Windows-Start)
  • SYSTEMEXIT (Windows-Shutdown)
  • RESTOREUP (Enlarge)
  • RESTOREDOWN (Shrink)
  • MENUPOPUP (Pop-Up)
  • MAXIMIZE (Maximize)
  • MINIMIZE (Minimize)
  • MAILBEEP (New Mail)
  • OPEN (Open Application)
  • CLOSE (Close Application)
  • APPGPFAULT (Program Error)

All available constants are defined in the registry under the path HKEY_CURRENT_USER -> AppEvents -> Schemes -> Apps -> .Default. Here, depending on the installed applications and your Windows version, you can surely find the one or another sound file and the associated constant.

Playback Modes

SND_ASYNC plays the sound in the background and let the program continue while playing.

SND_SYNC stops the program while playing and lets the program continue only after playing the sound completely.

SND_LOOP plays the sound in a loop over and over. Only when playing a new sound, or when you call PlaySound (nil, 0, 0) the playing is stopped.


About the Author

AvatarThe author has not added a profile short description yet.
Show Profile


Related Topics

Android Audio Recorder

Open Question | 5 Answers

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.


Ask your own question or write your own article on askingbox.com. That’s how it’s done.