我想用c#中的trackbar控件来实现音量的控制,应该怎么写代码?在线等大神。谢谢
展开全部
public partial class Form1 : Form
{
[DllImport("winmm.dll")]
internal static extern int waveOutGetVolume(IntPtr hwo, out uint dwVolume);
[DllImport("winmm.dll")]
internal static extern int waveOutSetVolume(IntPtr hwo, uint dwVolume);
public Form1()
{
InitializeComponent();
}
private void trackBar1_Scroll(object sender, EventArgs e)
{
uint currV = ushort.MaxValue / 2;
waveOutGetVolume(IntPtr.Zero, out currV);
ushort calcV = (ushort)(currV & 0x0000ffff);
int newV = ((ushort.MaxValue / 100) * trackBar1.Value);
uint newVol = (((uint)newV & 0x0000ffff) | ((uint)newV << 16));
waveOutSetVolume(IntPtr.Zero, newVol);
//下面这句是为了显示调整百分比
Text = Convert.ToString("Volume: " + trackBar1.Value + "%");
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询