C#怎样判断系统是否为静音?
看似简单的问题,我搜遍所有中文网,包括csdn各大门户网站, 没有找到源代码!
我百度,google无数次,终于在一个乌克兰的网站上找到源代码.
// by www.vjsdn.com 易学网.C#程序爱好者的快乐园!
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace VJSDN.Tech.Audio
{
/// <summary>
/// SOURCE CODE FROM THE WEBSITE.
/// LAST UPDATE:WWW.VJSDN.COM易学论坛,2009/08/03 by Jonny Sun
/// </summary>
public class SoundControl
{
#region declarations
const int MAXPNAMELEN = 32;
const int MIXER_SHORT_NAME_CHARS = 16;
const int MIXER_LONG_NAME_CHARS = 64;
[Flags]
enum MIXERLINE_LINEF : uint
{
ACTIVE = 0x00000001,
DISCONNECTED = 0x00008000,
SOURCE = 0x80000000
}
.....请下载附件. 请登录后下载.
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace VJSDN.Tech.Audio
{
/// <summary>
/// SOURCE CODE FROM THE WEBSITE.
/// LAST UPDATE:WWW.VJSDN.COM易学论坛,2009/08/03 by Jonny Sun
/// </summary>
public class SoundControl
{
#region declarations
const int MAXPNAMELEN = 32;
const int MIXER_SHORT_NAME_CHARS = 16;
const int MIXER_LONG_NAME_CHARS = 64;
[Flags]
enum MIXERLINE_LINEF : uint
{
ACTIVE = 0x00000001,
DISCONNECTED = 0x00008000,
SOURCE = 0x80000000
}
.....请下载附件. 请登录后下载.
测试按钮.Click();
private
void btnIsMute_Click(
object sender, EventArgs e)
{
//获取混音设备
SoundControl.MixerInfo mi = SoundControl.GetMixerControls();
//检查是否静音状态
bool ret = SoundControl.IsMuted(mi);
if (ret)
MessageBox.Show("系统是静音状态!");
else
MessageBox.Show("可以播放mp3啦!");
}
{
//获取混音设备
SoundControl.MixerInfo mi = SoundControl.GetMixerControls();
//检查是否静音状态
bool ret = SoundControl.IsMuted(mi);
if (ret)
MessageBox.Show("系统是静音状态!");
else
MessageBox.Show("可以播放mp3啦!");
}