网上转载的内容不知道正确与否待本人验证后,给予测试结果!!!
1 using System.Runtime.InteropServices; 2 public partial class Form1 : Form 3 { 4 private const int APPCOMMAND_VOLUME_MUTE = 0x80000; 5 private const int APPCOMMAND_VOLUME_UP = 0xA0000; 6 private const int APPCOMMAND_VOLUME_DOWN = 0x90000; 7 private const int WM_APPCOMMAND = 0x319; 8 [DllImport("user32.dll")] 9 public static extern IntPtr SendMessageW(IntPtr hWnd, int Msg, 10 IntPtr wParam, IntPtr lParam); 11 public Form1() 12 { 13 InitializeComponent(); 14 } 15 16 17 private void button1_Click(object sender, EventArgs e) 18 { 19 SendMessageW(this.Handle, WM_APPCOMMAND, this.Handle, 20 (IntPtr)APPCOMMAND_VOLUME_MUTE); 21 } 22 23 24 private void button2_Click(object sender, EventArgs e) 25 { 26 SendMessageW(this.Handle, WM_APPCOMMAND, this.Handle, 27 (IntPtr)APPCOMMAND_VOLUME_DOWN); 28 } 29 30 31 private void button3_Click(object sender, EventArgs e) 32 { 33 SendMessageW(this.Handle, WM_APPCOMMAND, this.Handle, 34 (IntPtr)APPCOMMAND_VOLUME_UP); 35 } 36 37 } 38 //button1_click事件让电脑系统静音;button2_click事件实现音量的减少;button3_click事件pc系统音量的添加。