在C#中调用API播放windows声音
2006-05-11 20:43
597 查看
这个函数能发出系统缺省的警告声.
using System.Runtime.InteropServices;
[DllImport("user32.dll")]
public static extern int MessageBeep(uint n);
private void button1_Click(object sender, System.EventArgs e)
{
MessageBeep(0xFFFFFFFF);
}
----===============================================
using System;
using System.Runtime.InteropServices;
namespace PlaySound
{
/// <summary>
/// Class1 的摘要说明。
/// </summary>
class Class1
{
//导入 Windows Beep() API 函数
[DllImport("kernel32.dll")]
private static extern bool Beep(int freq, int dur);
// 定义PlaySound()要使用的常数
public const int SND_FILENAME = 0x00020000;
public const int SND_ASYNC = 0x0001;
// 导入 Windows PlaySound() 函数
[DllImport("winmm.dll")]
public static extern bool PlaySound(string pszSound,
int hmod,
int fdwSound);
[STAThread]
static void Main(string[] args)
{
// 使用Ctrl+g发出蜂鸣声
Console.Write("/a");
Console.WriteLine("使用Ctrl+g发出蜂鸣声...");
Console.ReadLine();
// 使用 Windows API 发出蜂鸣声
Beep(800, 200);
Console.WriteLine("使用 Windows API 发出蜂鸣声...");
Console.ReadLine();
// 播放bells.wav文件
PlaySound("bells.wav",
0,
SND_FILENAME | SND_ASYNC);
Console.WriteLine("播放bells.wav文件...");
Console.ReadLine();
}
}
}
using System.Runtime.InteropServices;
[DllImport("user32.dll")]
public static extern int MessageBeep(uint n);
private void button1_Click(object sender, System.EventArgs e)
{
MessageBeep(0xFFFFFFFF);
}
----===============================================
using System;
using System.Runtime.InteropServices;
namespace PlaySound
{
/// <summary>
/// Class1 的摘要说明。
/// </summary>
class Class1
{
//导入 Windows Beep() API 函数
[DllImport("kernel32.dll")]
private static extern bool Beep(int freq, int dur);
// 定义PlaySound()要使用的常数
public const int SND_FILENAME = 0x00020000;
public const int SND_ASYNC = 0x0001;
// 导入 Windows PlaySound() 函数
[DllImport("winmm.dll")]
public static extern bool PlaySound(string pszSound,
int hmod,
int fdwSound);
[STAThread]
static void Main(string[] args)
{
// 使用Ctrl+g发出蜂鸣声
Console.Write("/a");
Console.WriteLine("使用Ctrl+g发出蜂鸣声...");
Console.ReadLine();
// 使用 Windows API 发出蜂鸣声
Beep(800, 200);
Console.WriteLine("使用 Windows API 发出蜂鸣声...");
Console.ReadLine();
// 播放bells.wav文件
PlaySound("bells.wav",
0,
SND_FILENAME | SND_ASYNC);
Console.WriteLine("播放bells.wav文件...");
Console.ReadLine();
}
}
}
相关文章推荐
- 在C#中如何调用windows的API进行关机操作!!!
- [C#] 如何调用Windows系统发送错误API
- 如何从C# 桌面应用程序调用Windows 8的WinRT API- WinRT 图表
- C#调用winmm.dll播放声音_中国创造
- C#播放声音的四种方法 +AxWindowsMediaPlayer的详细用法
- C#编写Windows桌面应用程序播放MP3声音文件
- C# winform使用系统API播放音乐(非调用控件)
- 如何从C#桌面应用程序中调用Windows 8的WinRT API (Metro API)
- c#调用api控制windows关机示例(可以重启/注销)
- C#调用WindowsMediaPlayer控件实现音乐播放(一)
- c#调用windows api C#简单游戏外挂制作(以Warcraft Ⅲ为例)
- 在C#中如何调用windows的API进行关机操作!!! [转]
- C# 用API播放声音
- 转:C#中调用Windows API时的…
- c#调用api控制windows关机示例
- C# windows窗口程序播放音乐
- C#使用Windows Media Player播放音频文件
- Python调用系统底层API播放wav文件的方法
- C#中调用WIN32的API
- C#中调用API