HP的笔记本,装个xp,快捷键没有音量显示,想做一个.这是音量控制的代码还有扑捉系统音量改变的消息~~~
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;
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
namespace WindowsApplication1
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{
public partial class Form1 : Form
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
public Form1()
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
InitializeComponent();
}
[DllImport("user32.dll", EntryPoint = "SendMessageA")]
public static extern int SendMessage(IntPtr handle, int wMsg, int wParam, int lParam);
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
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;
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
private void button1_Click(object sender, EventArgs e)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
SendMessage(Handle, WM_APPCOMMAND, 0x30292, APPCOMMAND_VOLUME_UP * 0x10000);
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
private void button2_Click(object sender, EventArgs e)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
SendMessage(Handle, WM_APPCOMMAND, 0x30292, APPCOMMAND_VOLUME_DOWN * 0x10000);
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
private void button3_Click(object sender, EventArgs e)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
SendMessage(Handle, WM_APPCOMMAND, 0x200EB0, APPCOMMAND_VOLUME_MUTE * 0x10000);
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
}
}
三个按钮分别为增加音量,减少音量,静音
以下代码捕捉系统消息,改变系统声音音量
protected override void WndProc(ref Message m)//监视Windows消息
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
const int WM_APPCOMMAND = 0x319;
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
switch (m.Msg)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
case WM_APPCOMMAND:
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
MessageBox.Show(m.ToString());
}
break;
}
base.WndProc(ref m); //将系统消息传递自父类的WndProc
}