Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I play music in an application?

Status
Not open for further replies.

jorjel

Programmer
Jul 22, 2005
1
RO
Hello, everyone! I need your help, please. I want to make my VisualC++ application to play a melody during the use of the program. Can this be done? How? And can the melody be "incorporated" in the .exe ?

Please help me! Thanks!
 
Yes. If you don't want to go into the depth of playing sounds, use PlaySound (more info here:
It can play a WAV file easily on each Windows Platform. Insert a WAV file as a resource in Visual C++ project (say as a WAVE type), then use the code like this to play:

Code:
#include <Mmsystem.h>
#pragma comment(lib, "Winmm.lib")
...

//IDR_WAVE_MY_SOUND = Resource ID of your WAV file
//hInst = HINSTANCE of the module this resource is in

//Play sound asynchronously
if(!PlaySound(MAKEINTRESOURCE(IDR_WAVE_MY_SOUND), hInst, SND_RESOURCE | SND_NODEFAULT | SND_NOWAIT | SND_NOSTOP | SND_ASYNC))
{
    //Error, sound not played
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top