#include using namespace std; #include // for sndPlaySoundA() // In addition to the above mentioned header file, you must also bind the winmm.lib library through the project property settings. void main() { // Each of the following lines of sndPlaySoundA code plays a single sound. // This first cluster plays sound files found on disk. // The flag SND_FILENAME signals that the sound is to be found in the explicitly named file (string of characters in double quotes) in the program's current directory. sndPlaySoundA("c:\\tada.wav", SND_FILENAME); // sndPlaySoundA() does not release control (and return to your program) until the sound is finished playing. Same as adding SND_SYNC sndPlaySoundA("tada.wav", SND_FILENAME|SND_ASYNC); // sndPlaySoundA() releases control back to you immediately, but continues to play the sound in the background. cout << "This is the next line of code . . .\n"; sndPlaySoundA("tada.wav", SND_FILENAME|SND_LOOP|SND_ASYNC); // After releasing control back to you, sndPlaySoundA() replays the sound 'ad infinitum' as a result of the flag SND_LOOP. // NOTE: Any new call to sndPlaySoundA() terminates currently playing sounds. // NOTE: You won't hear the second and third attempt to play "tada.wav" because they are played with the SND_ASYNC flag. // The "tada.wav" does start playing, but is interrupted within microseconds by the next call to sndPlaySoundA(). // This second cluster plays sound files using an alias defined in registry. // The flag SND_ALIAS signals this alternate interpretation of the string of characters in double quotes. sndPlaySoundA("SystemExit", SND_ALIAS); sndPlaySoundA("WindowsLogon", SND_ALIAS); sndPlaySoundA("WindowsLogoff", SND_ALIAS); // Note: The preceding calls to sndPlaySoundA are all SND_SYNC by default. You can use the SND_ASYNC flag as described above. // Because they are played with SND_SYNC, you hear them one after the next. system("pause"); }