阅读背景:

[译][C#]Vista的核心音频API主音量控制

来源:互联网 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Windows.Forms;
//CoreAudioApi支持Vista/Win7,下面的代码 是最早的API 函数 支持不好  不推荐使用
namespace SwitchIP
{
    class VolumeControl
    {
        [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;
        //增大音量
        public  void VolumeUp(){
            SendMessage(this.Handle, WM_APPCOMMAND, 0x30292, APPCOMMAND_VOLUME_UP * 0x10000);   
        }
        //降低音量
        public  void VolumeDown() {
            SendMessage(this.Handle, WM_APPCOMMAND, 0x30292, APPCOMMAND_VOLUME_DOWN * 0x10000); 
        }
        //该函数会自动在静音和非静音状态下切换
        public  void VolumeMute() {
            SendMessage(myForm.Handle, WM_APPCOMMAND, 0x200eb0, APPCOMMAND_VOLUME_MUTE * 0x10000); 
        }

            
    }
}using System;
using System.Collections.Gener



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: