C# 如何获取系统主音量 获取 系统主音量 10
1个回答
展开全部
[DllImport("winmm.dll")]
public static extern long waveOutSetVolume(UInt32 deviceID, UInt32 Volume);
[DllImport("winmm.dll")]
public static extern long waveOutGetVolume(UInt32 deviceID, out UInt32 Volume);
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// 设置滑块值为当前音量的值
GetVolume() ;
}
// 设置当前音量值到滑动条上
private void GetVolume()
{
UInt32 d, v;
d = 0;
long i = waveOutGetVolume(d, out v);
UInt32 vleft = v & 0xFFFF;
UInt32 vright = (v & 0xFFFF0000) >> 16;
trackBar1.Value = (int.Parse(vleft.ToString()) | int.Parse(vright.ToString())) * (this.trackBar1.Maximum - this.trackBar1.Minimum) / 0xFFFF;
}
// 滑块值改变时,修改音量值
private void trackBar1_Scroll(object sender, EventArgs e)
{
UInt32 Value = (System.UInt32)((double)0xffff * (double)trackBar1.Value / (double)(trackBar1.Maximum - trackBar1.Minimum));//先把trackbar的value值映射到0x0000~0xFFFF范围
//限制value的取值范围
if (Value < 0) Value = 0;
if (Value > 0xffff) Value = 0xffff;
UInt32 left = (System.UInt32)Value;//左声道音量
UInt32 right = (System.UInt32)Value;//右
waveOutSetVolume(0, left << 16 | right); //"<<"左移,“|”逻辑或运算
}
public static extern long waveOutSetVolume(UInt32 deviceID, UInt32 Volume);
[DllImport("winmm.dll")]
public static extern long waveOutGetVolume(UInt32 deviceID, out UInt32 Volume);
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// 设置滑块值为当前音量的值
GetVolume() ;
}
// 设置当前音量值到滑动条上
private void GetVolume()
{
UInt32 d, v;
d = 0;
long i = waveOutGetVolume(d, out v);
UInt32 vleft = v & 0xFFFF;
UInt32 vright = (v & 0xFFFF0000) >> 16;
trackBar1.Value = (int.Parse(vleft.ToString()) | int.Parse(vright.ToString())) * (this.trackBar1.Maximum - this.trackBar1.Minimum) / 0xFFFF;
}
// 滑块值改变时,修改音量值
private void trackBar1_Scroll(object sender, EventArgs e)
{
UInt32 Value = (System.UInt32)((double)0xffff * (double)trackBar1.Value / (double)(trackBar1.Maximum - trackBar1.Minimum));//先把trackbar的value值映射到0x0000~0xFFFF范围
//限制value的取值范围
if (Value < 0) Value = 0;
if (Value > 0xffff) Value = 0xffff;
UInt32 left = (System.UInt32)Value;//左声道音量
UInt32 right = (System.UInt32)Value;//右
waveOutSetVolume(0, left << 16 | right); //"<<"左移,“|”逻辑或运算
}
追问
看清楚了 是获取系统主音量 你这是波形音量
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询