This sample demonstrates how to play standard Windows sounds.
You can find the syssound sample project at:
- Start > Programs > Embarcadero RAD Studio > Samples > CPP > VCL > SysSound
- Subversion Repository for C++: http://radstudiodemos.svn.sourceforge.net/viewvc/radstudiodemos/branches/RadStudio_XE2/CPP/VCL/SysSound
This application creates a simple form with a list box and a button. The list box is populated at run time; the user can select one of the sounds displayed and hear it by clicking Play.
How to Use the Sample
- Navigate to Start > Programs > Embarcadero RAD Studio > Samples and open syssound.cbproj.
- Press F9 or choose Run > Run.
The project contains one source file, mainform.cpp, which contains the class of the main form.
TFormMain, the class for the main form, adds some standard Windows sounds to the list box at run time and plays them when the user clicks Play.
- The sound information is stored in a user-defined structure named soundinfo, which contains the sound name, value, and some additional information for displaying purposes.
- To play a sound, the Windows MessageBeep function is called.
- To add items at run time to the list box, the TListBox.Items method is used.
- The Selected property is used to check whether a certain item in the list box is selected and therefore the corresponding sound has to be played.
- When a sound is played, a label on the form is updated to display the MessageBeep function call.