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++ / May 2008

Tip: Looking for answers? Try searching our database.

How to create a sound from a VC++ .NET program

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Kueishiong Tu - 10 May 2008 16:15 GMT
I want to create a sound to alert the user when some event occurs.
How do I do it from my VC++ .NET window form program?
David Lowndes - 10 May 2008 18:09 GMT
>I want to create a sound to alert the user when some event occurs.
>How do I do it from my VC++ .NET window form program?

MessageBeep would probably be the easiest API to use. If you need a
more complex facility, have a look at the PlaySound API. For the .Net
world, it looks like similar facilities are available from the
System.Media namespace - SystemSound::Play for instance.

Dave
Kueishiong Tu - 10 May 2008 19:00 GMT
Dear Dave:

I use the following code to call MessageBeep from my VC++ .net window form
program
       
[DllImport("user32.dll", SetLastError=true)]
static bool MessageBeep(UINT type);

MessageBeep(-1);

However I do not hear a beep sound.

Also I do not see the System::Media namespace in my Visual Studio 2003 .NET.

Kueishiong Tu

> >I want to create a sound to alert the user when some event occurs.
> >How do I do it from my VC++ .NET window form program?
[quoted text clipped - 5 lines]
>
> Dave
David Lowndes - 10 May 2008 23:39 GMT
>I use the following code to call MessageBeep from my VC++ .net window form
>program
>       
>[DllImport("user32.dll", SetLastError=true)]
>static bool MessageBeep(UINT type);

You don't need to go to that rigmarole - this is C++ not C# :)

Just #include<windows.h> and add the call to the API.

>MessageBeep(-1);

Try MessageBeep(MB_OK) - it should produce whatever system sound you
have set up in the Control Panel Sound setting.

>Also I do not see the System::Media namespace in my Visual Studio 2003 .NET.

I don't have VS2003 installed, but the following works for me with
VS2008:

#include "stdafx.h"
#include<windows.h>

#pragma comment( lib, "User32.lib" )

using namespace System;

int main(array<System::String ^> ^args)
{
   Console::WriteLine(L"Hello World");
   MessageBeep( -1 );

   System::Media::SystemSounds::Beep->Play();
   return 0;
}

Dave
Kueishiong Tu - 11 May 2008 00:52 GMT
Dear Dave:

> >I use the following code to call MessageBeep from my VC++ .net window form
> >program
[quoted text clipped - 5 lines]
>
> Just #include<windows.h> and add the call to the API.

If I don't do the DllImport, the IDE will complain unresolved token
"MessageBeep" when I try to build the solution in VS2003 VC++ .NET.

> I don't have VS2003 installed, but the following works for me with
> VS2008:
[quoted text clipped - 14 lines]
>     return 0;
> }

I try the same code on my VS2008 VC++ express, but I still get no sound even
I turn the speaker to the loudest level and my window media player does play
sound.

Kueishiong Tu
David Lowndes - 11 May 2008 09:34 GMT
>> I don't have VS2003 installed, but the following works for me with
>> VS2008:
[quoted text clipped - 18 lines]
>I turn the speaker to the loudest level and my window media player does play
>sound.

If you use the Control Panel, Sound applet and play the default beep
from there, does that work?

Dave
Kueishiong Tu - 11 May 2008 13:25 GMT
> If you use the Control Panel, Sound applet and play the default beep
> from there, does that work?
>
> Dave

It does not initially. I fix it. Now it works fine. Thank you very much for
your help.

Kueishiong Tu

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.