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
            }
  • 相关阅读:
    poj3032
    poj2603
    poj2019
    poj2369
    AVI 录像功能压缩算法设置
    陆其明的新书《脚本驱动的应用软件开发方法与实践》
    c# 动态编译
    !!!分享:把bmp格式的图片转化为AVI格式的视频操作的封装类其中对于AVI API的函数的使用较为完整
    视频文件格式和视频编码方式
    activex 控件的id 定义位置+使用ocx控件的客户端程序中对控件定义的文件中控件id定义的位置
  • 原文地址:https://www.cnblogs.com/zhahost/p/1212416.html
Copyright © 2011-2022 走看看