Monday, November 18
Play Sound in Your CPP Program
Till now, all of us have coded C++ programs on the black & white console, some know how to color the text on string.
Lets go a step ahead and introduce sound being played as your program runs.
Interesting, Right?
Yes, you'll have a new effect to add in your code :-)
How to Do?
The amazing sound feature consists of just two lines,
1. The PlaySound function call.
2. The header file that contains this function.
Code:
#include<iostream.h>
#include<conio.h>
#include <string.h>
#include <windows.h>
using namespace std;
int main()
{
PlaySound("file_name.wav",NULL,SND_FILENAME|SND_LOOP);
// PlaySound method is defined in windows.h
// file_name is the name of your sound file in .wav format
getche();
return 0;
}
Note:
Your .wav file should be in the same location as that of ur .cpp file.
More:
For details and possible values of parameters in PlaySound function visit the link below
http://msdn.microsoft.com/en-us/library/windows/desktop/dd743680(v=vs.85).aspx
Include sound in your programs and have FUN
Stay Blessed :-)
Regards
Lets go a step ahead and introduce sound being played as your program runs.
Interesting, Right?
Yes, you'll have a new effect to add in your code :-)
How to Do?
The amazing sound feature consists of just two lines,
1. The PlaySound function call.
2. The header file that contains this function.
Code:
#include<iostream.h>
#include<conio.h>
#include <string.h>
#include <windows.h>
using namespace std;
int main()
{
PlaySound("file_name.wav",NULL,SND_FILENAME|SND_LOOP);
// PlaySound method is defined in windows.h
// file_name is the name of your sound file in .wav format
getche();
return 0;
}
Note:
Your .wav file should be in the same location as that of ur .cpp file.
More:
For details and possible values of parameters in PlaySound function visit the link below
http://msdn.microsoft.com/en-us/library/windows/desktop/dd743680(v=vs.85).aspx
Include sound in your programs and have FUN
Stay Blessed :-)
Regards
Its Really Interesting ,,,,
ReplyDeleteglad you liked it sir :)
ReplyDeletegreat........ !! :)
ReplyDelete