473,387 Members | 1,541 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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

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?
Jun 27 '08 #1
6 2664
>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
Jun 27 '08 #2
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

"David Lowndes" wrote:
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
Jun 27 '08 #3
>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.hand 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
Jun 27 '08 #4
Dear Dave:

"David Lowndes" wrote:
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.hand 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:

#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;
}
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
Jun 27 '08 #5
>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;
}

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.
If you use the Control Panel, Sound applet and play the default beep
from there, does that work?

Dave
Jun 27 '08 #6
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
Jun 27 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Xanax | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi all, I am interested in developing my own decoding software for CW , PSK , FSK etc used on the Ham radio bands. Is it possible to use MS...
3
by: Michael Lauzon | last post by:
This is not for a class, I have a group on SourceForge, this is what one of the Developers is asking; the more advanced you can make it right off all the better!: Can someone please create...
2
by: brazilnut52 | last post by:
I am going to outline the steps I go through to produce the problem. Hopefully this will help you understand the problem better I have created a simple COM DLL in .NET by using the COM class...
15
by: Viviana Vc | last post by:
How can I programatically do the equivalent of the following: cacls "C:\Program Files\test" /T /G Everyone:f ? Thanks, Viv
17
by: Ralph | last post by:
Hi all, Recently I have tried to create a static lib using MS VC++. The following are some of the excerpt of my codes: ********* MyFirstStaticLib.c ******************* #include...
11
by: Tatu Portin | last post by:
Have this kind of struct: typedef struct { char **user_comments; /* ... */ } vorbis_comment; /* prototype */ char * read_vorbis_string ( FILE *sc);
2
by: Peteroid | last post by:
Can anybody point me to or give a simple source example of a managed C++ application that can play a wav sound file? I know a little about playSound(), but it doesn't seem to like to compile (even...
1
by: richardbustarde | last post by:
Using VC++ .NET, How can you 1. Play sound or 2. start BEEP sound
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.