首页 > 学院 > 开发设计 > 正文

C# 控制系统音量,静音 (加减按钮形式)

2019-11-17 04:07:47
字体:
来源:转载
供稿:网友
view plaincopy to clipboardPRint?
·········10········20········30········40········50········60········70········80········90········100·······110·······120·······130·······140·······150
using System;   
using System.Collections.Generic;   
using System.ComponentModel;   
using System.Data;   
using System.Drawing;   
using System.Text;   
using System.Windows.Forms;   
    
using System.Runtime.InteropServices;   
  
namespace VolumnSet   
{   
    public partial class Form1 : Form   
    {   
  
    
  
        [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 Form1()   
        {   
            InitializeComponent();   
  
        }   
        private void button1_Click(object sender, EventArgs e)   
        {   
  
             //加音量   
            SendMessage(this  
  .Handle, WM_APPCOMMAND, 0x30292, APPCOMMAND_VOLUME_UP * 0x10000);   
        }   
  
        private void button2_Click(object sender, EventArgs e)   
        {   
  
             //减音量   
            SendMessage(this.Handle, WM_APPCOMMAND, 0x30292, APPCOMMAND_VOLUME_DOWN * 0x10000);   
        }   
  
          
  
        private void checkBox1_CheckedChanged(object sender, EventArgs e)   
        {   
  
             //静音   
            SendMessage(this.Handle, WM_APPCOMMAND, 0x200eb0, APPCOMMAND_VOLUME_MUTE * 0x10000);   
        }   
    }   
}  
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表