日期:2014-05-18  浏览次数:21072 次

一个有关MessageBeep的问题
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace 喇叭响
{
  public partial class Form1 : Form
  {
  [DllImport("user32.dll")]
  public static extern bool MessageBeep(uint uType);

  public Form1()
  {
  InitializeComponent();
  }

  private void button1_Click(object sender, EventArgs e)
  {

  MessageBeep(1);

  }
  }
}
窗体上就是一个按钮,怎么运行后点击按钮不发出声音啊?这是为什么?messagebeep到底怎么使用啊?
最好把运行后可以发出声音的代码压缩包发到我邮箱里,谢谢!邮箱:467503768@qq.com

------解决方案--------------------
C# code


using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace 喇叭响
{
  public partial class Form1 : Form
  {
    public enum BeepType
    {
      SimpleBeep = -1,
      IconAsterisk = 0x00000040,
      IconExclamation = 0x00000030,
      IconHand = 0x00000010,
      IconQuestion = 0x00000020,
      Ok = 0x00000000,
    }

  [DllImport("user32.dll")]
  public static extern bool MessageBeep(BeepType beepType); 
  public Form1()
  {
     InitializeComponent();
  }

  private void button1_Click(object sender, EventArgs e)
  {

     MessageBeep(BeepType.SimpleBeep); 
  }
 }
}

------解决方案--------------------
C# code

    //使用MessageBeep(unit uType):需添加 using System.Runtime.InteropServices;
   public const int MB_ICONEXCLAMATION = 48;
   [DllImport("user32.dll")]
   public static extern bool MessageBeep(uint uType);
   MessageBeep( MB_ICONEXCLAMATION );

------解决方案--------------------
探讨

引用:
C# code


//使用MessageBeep(unit uType):需添加 using System.Runtime.InteropServices;
public const int MB_ICONEXCLAMATION = 48;
[DllImport("user32.dll")]
public static extern bool Messa……

------解决方案--------------------
其实非常简单。
C# code

  Console.Beep();//这一句就可以搞定了。