Scott Hanselman

How many ways to Beep and Make Noise in .NET and C#

August 01, 2003 Comment on this post [0] Posted in Web Services | XML
Sponsored By

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.

facebook twitter subscribe
About   Newsletter
Hosting By
Hosted in an Azure App Service

Comments are closed.

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.