zoukankan      html  css  js  c++  java
  • c# 系统音量的控制

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Diagnostics;
    using System.Runtime.InteropServices;   


    namespace WindowsApplication1
    {
        
    public partial class Form1 : Form
       
    {
            
    public Form1()
           
    {
                InitializeComponent();            
            }

            
            [DllImport(
    "user32.dll", EntryPoint = "SendMessageA")]
            
    public static extern int SendMessage(IntPtr handle, int wMsg, int wParam, int lParam);   

            
    private const int WM_APPCOMMAND = 0x319;
            
    private const int APPCOMMAND_VOLUME_UP = 10;
            
    private const int APPCOMMAND_VOLUME_DOWN = 9;
            
    private const int APPCOMMAND_VOLUME_MUTE = 8;

            
    private void button1_Click(object sender, EventArgs e)
           
    {
                SendMessage(Handle, WM_APPCOMMAND, 
    0x30292, APPCOMMAND_VOLUME_UP * 0x10000);
                
            }


            
    private void button2_Click(object sender, EventArgs e)
           
    {
                SendMessage(Handle, WM_APPCOMMAND, 
    0x30292, APPCOMMAND_VOLUME_DOWN * 0x10000);
            }


            
    private void button3_Click(object sender, EventArgs e)
           
    {
                SendMessage(Handle, WM_APPCOMMAND, 
    0x200EB0, APPCOMMAND_VOLUME_MUTE * 0x10000);
            }



        }

    }

    三个按钮分别为增加音量,减少音量,静音

    以下代码捕捉系统消息,改变系统声音音量



    protected override void WndProc(ref Message m)//监视Windows消息
            {
                
    const int WM_APPCOMMAND = 0x319;

                
    switch (m.Msg)
               
    {
                    
    case WM_APPCOMMAND:
                       
    {
                            MessageBox.Show(m.ToString());
                        }

                    
    break;
                }

                
                
    base.WndProc(ref m); //将系统消息传递自父类的WndProc
            }
  • 相关阅读:
    Linq的一些常见Demo
    有一名员工发现日历已经7天没有翻了,于是他连着翻了7页,7天的总和刚好是138,问这一天是几号?
    20块钱,1块钱1瓶,两个空瓶子可以换一瓶,问最多可以喝几瓶?
    【转】Java编程之字符集问题研究
    Reset / Validate Buffer
    Article Master Data Deviation
    STAD Parameters
    Linux11.2 MySQL常用命令
    Linux11.1 设置更改Mysql的root密码及连接mysql
    Linux5.10 告警系统
  • 原文地址:https://www.cnblogs.com/zhahost/p/1212416.html
Copyright © 2011-2022 走看看