Búsqueda


Categorías

C# [15]
PHP [6]
Zend [1]
FileMaker [1]
.NET [6]
CVS [3]
General [9]
Javascript [2]
Paypal [1]
.NET Compact Framework [3]
C++ [1]
mysql [4]
Linux [1]

Últimos post

Dónde guardar los archivos de configuración en ClickOnce
phpinfo: Valores en error_reporting
Notes about Zend Server and Zend Studio setup
What's new in C# 4
Resolving a 'sticky tag is not a branch' error
Resumen del CodeCamp
CodeCamp Tarragona 2009
Acerca de la calidad del código
ClickOnce en Linux
Programando en PHP (y con CVS) en Visual Studio 2008

Sindicación

RSS 0.90
RSS 1.0
RSS 2.0
Atom 0.3

Make a beep using internal PC speaker using C#

ctg | 17 Julio, 2008 23:56

Some computers doesn't enable sound card or simply, doesn't have it.

If you want make a beep to force to user to pay attention you can also use P/Invoke to call Beep funciton on Kernel32.dll.

It takes two arguments, the first one the frequency, and the second one the duration and returns a bool for success.

Frequency must be from 37 to 32,767.

using System.Runtime.InteropServices;

public class Foo
{
    [DllImport("Kernel32.dll")]
    public static extern bool Beep(UInt32 frequency, UInt32 duration);

    public static void beepTime()
    {
        Beep(1000, 300);
        System.Threading.Thread.Sleep(300);
        Beep(2000, 400);
        System.Threading.Thread.Sleep(300);
        Beep(500, 200);
        System.Threading.Thread.Sleep(300);
    }
}

Posted in C# . Comentario: (0). Retroenlaces:(0). Enlace
«Next post | Previous post»

Comentarios

Deja un comentario
















En que mes se celebra la navidad: