Home > Windows API > Using sndPlaySound to play a wave file!

Using sndPlaySound to play a wave file!

This is how we do it…

// Include file
#include "mmsystem.h"

// Link to this library
#pragma comment( lib, "winmm.lib" ) 

int main( int argc, char **argv )
{
    // Will block till the whole file is played, use SND_ASYNC to play asynchronously
    sndPlaySound( "c://windows//media//ding.wav", SND_SYNC ); 

    // Play for ever, should use SND_ASYNC
    sndPlaySound( "c://windows//media//ding.wav", SND_ASYNC|SND_LOOP ); 

    // Sleep for 5 seconds
    Sleep( 5000 ); 

    // Enough is enough stop making that stupid noise
    sndPlaySound( NULL, SND_SYNC ); 

    return 0;
}// End main
Advertisements
  1. Friend
    September 14, 2007 at 11:33 am

    Cool

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: