K
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?
How do I do it from my VC++ .NET window form program?
How do I do it from my VC++ .NET window form program?
program
[DllImport("user32.dll", SetLastError=true)]
static bool MessageBeep(UINT type);
Just #include said:MessageBeep(-1);
Also I do not see the System::Media namespace in my Visual Studio 2003 .NET.
David Lowndes said: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.
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