VCL.SysSound Sample

From RAD Studio XE2 Code Examples
Jump to: navigation, search

Language:

This sample demonstrates how to play standard Windows sounds.

Contents

Location

You can find the syssound sample project at:

Description

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

  1. Navigate to Start > Programs > Embarcadero RAD Studio > Samples and open syssound.cbproj.
  2. Press F9 or choose Run > Run.

Files

The project contains one source file, mainform.cpp, which contains the class of the main form.

Classes

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.

Implementation

  • 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.

Uses

See Also

Personal tools
Previous Versions