基本信息
源码名称:WIN7、10 主音量控制 示例源码
源码大小:0.08M
文件格式:.rar
开发语言:C#
更新时间:2018-03-25
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559

本次赞助数额为: 10 元 
   源码介绍

WIN7、10 主音量控制,输入数字或滑动条控制音量。4组全局快捷键控制音量加减、窗口显示隐藏、结束进程包括自身、静音。程序只允许一个实例。

用到多个类,所以详细请下载源码。


using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Collections;

namespace VolumeTool
{
    public delegate void HotkeyEventHandler(int HotKeyID);
    public class AppHotkey : IMessageFilter
    {
        Hashtable keyIDs = new Hashtable();
        IntPtr hWnd;
        static public int Onehotkey;
        static public int Twohotkey;
        static public int Threehotkey;
        static public int Fourhotkey;
        static public int Fivehotkey;
        public event HotkeyEventHandler OnHotkey;
        public enum KeyFlags
        {
            MOD_ALT = 0x1,
            MOD_CONTROL = 0x2,
            MOD_SHIFT = 0x4,
            MOD_WIN = 0x8
        }
        [DllImport("user32.dll")]
        public static extern uint RegisterHotKey(IntPtr hWnd, uint id, uint fsModifiers, uint vk);
        [DllImport("user32.dll")]
        public static extern uint UnregisterHotKey(IntPtr hWnd, uint id);
        [DllImport("kernel32.dll")]
        public static extern uint GlobalAddAtom(string lpString);
        [DllImport("kernel32.dll")]
        public static extern uint GlobalDeleteAtom(uint nAtom);
        public AppHotkey(IntPtr hWnd)
        {
            this.hWnd = hWnd;
            Application.AddMessageFilter(this);
        }
        public int RegisterHotkey(Keys Key, KeyFlags keyflags)
        {
            uint hotkeyid = GlobalAddAtom(Guid.NewGuid().ToString());
            RegisterHotKey(hWnd, hotkeyid, (uint)keyflags, (uint)Key); //注册全局组合键
            // RegisterHotKey(hWnd, hotkeyid, 0, (uint)Key); //注册全局组单键
            keyIDs.Add(hotkeyid, hotkeyid);
            return (int)hotkeyid;
        }
        public void UnregisterHotkeys()
        {
            Application.RemoveMessageFilter(this);
            foreach (uint key in keyIDs.Values)
            {
                UnregisterHotKey(hWnd, key);
                GlobalDeleteAtom(key);
            }
        }
        public bool PreFilterMessage(ref Message m)
        {
            if (m.Msg == 0x312)
            {
                if (OnHotkey != null)
                {
                    foreach (uint key in keyIDs.Values)
                    {
                        if ((uint)m.WParam == key)
                        {
                            OnHotkey((int)m.WParam);
                            return true;
                        }
                    }
                }
            }
            return false;
        }
    }
}


using System;
using System.Threading;
using System.Diagnostics;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace VolumeTool
{
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            bool ret;
            Mutex mutex = new System.Threading.Mutex(true, Application.ProductName, out ret);
            if (ret)
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new GetAndSetVolumeForm());
                //   Main   为你程序的主窗体,如果是控制台程序不用这句   
                mutex.ReleaseMutex();
            }
            else
            {
                Application.Exit();//退出程序   
            }
        }
    }
}