用C#程序获取系统主音量并设置系统主音量?
[DllImport("Winmm.dll")]privatestaticexternintwaveOutSetVolume(inthwo,System.UInt32pd...
[DllImport("Winmm.dll")]
private static extern int waveOutSetVolume(int hwo, System.UInt32 pdwVolume);//设置音量
[DllImport("Winmm.dll")]
private static extern uint waveOutGetVolume(int hwo, out System.UInt32 pdwVolume); //获取音量
我测试了一下:以上方法也都是获取系统或设置波形的音量值????求:获取或设置系统声音主音量值的思路及源码或解决方案……谢谢 展开
private static extern int waveOutSetVolume(int hwo, System.UInt32 pdwVolume);//设置音量
[DllImport("Winmm.dll")]
private static extern uint waveOutGetVolume(int hwo, out System.UInt32 pdwVolume); //获取音量
我测试了一下:以上方法也都是获取系统或设置波形的音量值????求:获取或设置系统声音主音量值的思路及源码或解决方案……谢谢 展开
1个回答
展开全部
不知道这个是不是你需要的
using System.Runtime.InteropServices; //加入命名空间
[DllImport("winmm.dll")] //引用winmm.dll
public static extern long waveOutSetVolume(uint deviceID, uint Volume); //参数为uint
//音量调节
private void progressBar1_MouseDown(object sender, MouseEventArgs e)
{
int tmp = 46 + e.X;
if (tmp > 160) tmp = 160;
labelVoiceUpDown.Location = new Point(tmp, 8);
progressBar1.Value = e.X;
UInt32 left = (UInt32)progressBar1.Value * 500;//左声道音量
UInt32 right= (UInt32)progressBar1.Value *500;//右声道音量
waveOutSetVolume(0, left<<16|right);
}
一、引入API定义
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, uint wParam, uint lParam);
const uint WM_APPCOMMAND = 0x319;
const uint APPCOMMAND_VOLUME_UP = 0x0a;
const uint APPCOMMAND_VOLUME_DOWN = 0x09;
const uint APPCOMMAND_VOLUME_MUTE = 0x08;
二、 提高音量
SendMessage(this.Handle, WM_APPCOMMAND, 0x30292, APPCOMMAND_VOLUME_UP * 0x10000);
三、 降低音量
SendMessage(this.Handle, WM_APPCOMMAND, 0x30292, APPCOMMAND_VOLUME_DOWN * 0x10000);
四、 静音与恢复(执行2次恢复原状态)
SendMessage(this.Handle, WM_APPCOMMAND, 0x200eb0, APPCOMMAND_VOLUME_MUTE * 0x10000);
using System.Runtime.InteropServices; //加入命名空间
[DllImport("winmm.dll")] //引用winmm.dll
public static extern long waveOutSetVolume(uint deviceID, uint Volume); //参数为uint
//音量调节
private void progressBar1_MouseDown(object sender, MouseEventArgs e)
{
int tmp = 46 + e.X;
if (tmp > 160) tmp = 160;
labelVoiceUpDown.Location = new Point(tmp, 8);
progressBar1.Value = e.X;
UInt32 left = (UInt32)progressBar1.Value * 500;//左声道音量
UInt32 right= (UInt32)progressBar1.Value *500;//右声道音量
waveOutSetVolume(0, left<<16|right);
}
一、引入API定义
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, uint wParam, uint lParam);
const uint WM_APPCOMMAND = 0x319;
const uint APPCOMMAND_VOLUME_UP = 0x0a;
const uint APPCOMMAND_VOLUME_DOWN = 0x09;
const uint APPCOMMAND_VOLUME_MUTE = 0x08;
二、 提高音量
SendMessage(this.Handle, WM_APPCOMMAND, 0x30292, APPCOMMAND_VOLUME_UP * 0x10000);
三、 降低音量
SendMessage(this.Handle, WM_APPCOMMAND, 0x30292, APPCOMMAND_VOLUME_DOWN * 0x10000);
四、 静音与恢复(执行2次恢复原状态)
SendMessage(this.Handle, WM_APPCOMMAND, 0x200eb0, APPCOMMAND_VOLUME_MUTE * 0x10000);
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询