The views expressed on this weblog are mine alone and do not necessarily reflect the views of my employer.
 Friday, August 01, 2003
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
);


Updated Link to this post 11:52:40 AM  #    comment []  trackback []