How many ways to Beep and Make Noise in .NET and C#
At the PADNUG meeting last night the question (Lord knows why this always comes up :) on how to make the system "beep" was asked. Here's two kinds of beeps, and links to some source.
The "PC Beep," including frequency and duration:
using System.Runtime.InteropServices;
class MainClass
{
[DllImport("kernel32.dll")]
public static extern bool Beep(int freq,int duration);
public static void Main(string[] args)
{
Beep(1000,1000);
Beep(2000,500);
}
}
The considerably more interesting "MessageBeep" (via BradA) that uses the Wav files that are configured in the Sounds Control Panel.
public enum MessageBeepType
{
Default = -1,
Ok = 0x00000000,
Error = 0x00000010,
Question = 0x00000020,
Warning = 0x00000030,
Information = 0x00000040,
}
[DllImport("user32.dll", SetLastError=true)]
public static extern bool MessageBeep(
MessageBeepType type
);
About Scott
Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.
About Newsletter
Comments are closed.