Short little sound files of chicken, horses, dogs, cars, trains and other annoying things is the realm of the wave file (.wav). These are easy to play and guaranteed to confuse grandpapa. Again, we are using Windows' sound workhorse winmm.lib file. Ze function this time is PlaySound(). Here is ze C++ console code.
Ze WAVE sound file player
// play a sound with PlaySound() from the winmm.lib
// For DevCpp add the library libwinmm.a to the linker via
// Project/Project Options/Parameters/Add Library
// a Dev-C++ tested console application by vegaseat 19dec2004
#include <cstdio> // getchar()
#include <windows.h> // PlaySound()
#define SND_FILENAME 0x20000 // from mmsystem.h
#define SND_LOOP 8
#define SND_ASYNC 1
#define SND_ALIAS 0x10000
using namespace std;
int main()
{
// pick a wave file supplied by Windows XP or one of your own ...
char soundfile[] = "C:/Windows/Media/chimes.wav";
// play sound as loop, warning - can be vexatious!!!
PlaySound(soundfile,NULL,SND_FILENAME|SND_LOOP|SND_ASYNC);
// without SND_LOOP it just plays it once
//PlaySound(soundfile,NULL,SND_FILENAME|SND_ASYNC);
// play the system exit sound if set
//PlaySound("SystemExit",NULL,SND_ALIAS);
getchar(); // wait
return 0;
}
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague
Nauro 0 Newbie Poster
danibootstrap 13 Light Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.