---
title: "c#中用声音提示报警 "
author: "devilhand"
date: "2012-03-14T09:51:30Z"
tags: []
categories: ["编程语言"]
slug: "c"
draft: false
lastmod: "2012-03-14T09:51:30Z"
id: 1452920
url: "https://devilhand.iteye.com/blog/1452920"
---

using System;  
using System.Runtime.InteropServices;  
调用 Interaction.Beep();

**使用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 );

**调用Beep(Int freq,int duration)函数**

  \[DllImport("kernel32.dll")]  
  public static extern bool Beep(int freq,int duration);

Beep(800,300);

**调用PlaySound(string pszSound,int hmod,int fdwSound)**  
  \[DllImport("winmm.dll")]  
  public static extern bool PlaySound(string pszSound,int hmod,int fdwSound);  
  public const int SND\_FILENAME = 0x00020000;  
  public const int SND\_ASYNC = 0x0001;

PlaySound("提示时奏幻想空间.WAV",0,SND\_ASYNC|SND\_FILENAME);