Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / February 2005

Tip: Looking for answers? Try searching our database.

PlaySound with Resource Question

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Joe Thompson - 10 Feb 2005 17:29 GMT
Hi,

I am trying to use PlaySound in a VC++.net Windows app (VS 2003). I can use
it to play a file but now I want to play it from a resource.  I have two
questions:

How do I add a wav file to my project as a resource (steps please)

How do I call PlaySound once that I have the wav file as part of the resource.

Thank you,
Joe
Antti Keskinen - 10 Feb 2005 22:42 GMT
Hello !

This is more simpler than you might imagine.

Your first task is to add the actual wave file into your project as a
resource. To accomplish this, the wave file should be in standard PCM wave
format. Now proceed with the following steps:

1. Go to the solution view of Visual Studio, and click on the project name.
Then right-click, choose 'Add -> Add Resource' from the pop-up menu
2. In the "Add Resource" dialog that opens, click on the 'Import' button.
3. This will open a file browser. Now, change file types to view to 'All
files (*.*)'.
4. Browse to the directory where your audio file is stored, click on it's
name and choose 'Open'.
5. A dialog box is displayed, asking for the resource name. Use whatever ID,
such as IDR_MYWAVEFILE.
6. The resource is now added

In order to play back the resource file, you use PlaySound directly. First,
make sure that the compilation unit (.cpp file) that is supposed to play the
sound has a) included "resource.h" and b) has some means to get the instance
handle of the executable. This is the handle passed to WinMain when your
program starts. In MFC, you can use AfxGetResourceHandle() to obtain this
handle.

When these pre-steps are taken care of, playing the sound is a matter of
calling:

PlaySound( MAKEINTRESOURCE(IDR_MYWAVEFILE), <instance handle here>,
SND_RESOURCE );

You should hear the sound play through once. If you wish to loop it, use the
necessary flags for PlaySound, just as if you were playing back a file.

Hope this helps.

-Antti Keskinen

> Hi,
>
[quoted text clipped - 10 lines]
> Thank you,
> Joe
Joe Thompson - 10 Feb 2005 23:09 GMT
Hi Antti,

This is exactly what I was looking for - thank you for taking the time to
explain it so well.  I am using NULL for the Handle and it seems to work.

Thank you,
Joe

> Hello !
>
[quoted text clipped - 49 lines]
> > Thank you,
> > Joe

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.