Adding Multimedia Component

To create a real excitement multimedia is must. Different sound effects and the rich graphics when combine in one program gives a real rich environment. This article demonstrates how to play sound asynchronously while our application runs. This application has been created using MFC AppWizard. Then we have inserted Multimedia component from the component gallery. To do so you have to perform following steps:

(a) From the 'Project' menu select 'Add To Project' menu option.

(b) From the new popup menu that appears select 'Components and Controls'. A dialog box would be   
     popped up.

(c) From the dialog box select 'Visual C++ Components'. A dialog box would be popped up.

(d) Double click on 'Windows Multimedia Library' component to insert it.


By inserting the multimedia component we can use the PlaySound( ) function to play a sound file that too asynchronously so that we can do other work at the same time. This function takes three parameters: First one can be a filename or the ID for the sound. The filename should be provided in the form of string. The ID would be a number which we get when we insert the sound file in the resource. The second parameter should be NULL. The third parameter should be SND_FILENAME if we have provided filename for the sound as the first parameter or SND_RESOURCE if we have provided ID for the sound. In this program we have provided the filename and so we have used SND_FILENAME as the third parameter. We have also used SND_ASYNC and SND_LOOP in combination with SND_FILENAME to make the function play sound asynchronously and in continuous loop respectively. The PlaySound( )function needs 'mmsystem.h' file as the header file and 'winmm.lib' as the library file to link the actual DLL. Both files are included and linked automatically when we insert the control in our project.

To create a real excitement multimedia is must. Different sound effects and the rich graphics when combine in one program gives a real rich environment. This article demonstrates how to play sound asyncronously while our application runs.


This application has been created using MFC AppWizard. Then we have inserted Multimedia component from the component gallery. To do so you have to perform following steps:
(a) From the 'Project' menu select 'Add To Project' menu option.
(b) From the new popup menu that appears select 'Components and Controls'. A dialog box would be popped up.
(c) From the dialog box select 'Visual C++ Components'. A dialog box would be popped up.
(d) Double click on 'Windows Multimedia Library' component to insert it.

By inserting the multimedia component we can use the PlaySound( ) function to play a sound file that too asyncronously so that we can do other work at the same time. This function takes three parameters: First one can be a filename or the ID for the sound. The filename should be provided in the form of string. The ID would be a number which we get when we insert the sound file in the resource. The second parameter should be NULL. The third parameter should be SND_FILENAME if we have provided filename for the sound as the first parameter or SND_RESOURCE if we have provided ID for the sound. In this program we have provided the filaname and so we have used SND_FILENAME as the third parameter. We have also used SND_ASYNC and SND_LOOP in combination with SND_FILENAME to make the function play sound asyncronously and in continous loop respectively. The PlaySound( ) function needs 'mmsystem.h' file as the header file and 'winmm.lib' as the library file to link the actual DLL. Both files are included and linked automatically when we insert the control in our project.