Delphi: Play System-Sounds
Tutorial by Delphian | Last update on 2022-12-29 | Created on 2012-06-29
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; PlaySound('SYSTEMSTART', 0, SND_ASYNC);
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:
- SYSTEMEXCLAMATION (Note)
- SYSTEMHAND (Critical Stop)
- SYSTEMQUESTION (Question)
- SYSTEMSTART (Windows-Start)
- SYSTEMEXIT (Windows-Shutdown)
- SYSTEMASTERIX (Star)
- RESTOREUP (Enlarge)
- RESTOREDOWN (Shrink)
- MENUCOMMAND (Menu)
- 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
The author has not added a profile short description yet.
Show Profile
Related Topics
Lazarus: Program without GUI - Many WSRegister Errors
Question | 6 Answers
MIME Types of Microsoft Office File Formats
Info | 0 Comments
Delphi: Global Treatment of Errors (Exceptions)
Tutorial | 0 Comments
Delphi/Lazarus: Is the ALT, SHIFT or CTRL key pressed?
Tutorial | 0 Comments
Create Custom Error Pages for Website
Tip | 0 Comments
Delphi: System-Wide HotKey
Tutorial | 1 Comment
The Secure Password
Info | 0 Comments
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.
Participate
Ask your own question or write your own article on askingbox.com. That’s how it’s done.