现在的位置: 首页 > 综合 > 正文

C#&.NET Framework中的Beep

2012年07月29日 ⁄ 综合 ⁄ 共 708字 ⁄ 字号 评论关闭

原文:Beep Sound in C#\.NET Framework


目前的.NET framework1.0/1.1不支持Beep(),因此我们只能通过以下几种方法达到目标:
(a) 调用Win32 API:
    [DllImport("kernal32.dll")]
    public static extern bool Beep(int freq, int duration);

(b) MessageBeepType
    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);

(c)     使用VB assembly中的Beep()
添加一个到Microsoft.VisualBasic.dll的引用,然后调用:
    Microsoft.VisualBasic.Interaction.Beep()


在Whidbey (.NET Framework V2.0)将在Framework中直接支持Beep():
        Console.Beep();
        Console.Beep(int frequency, in duration);

抱歉!评论已关闭.