惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google DeepMind News
Google DeepMind News
博客园 - 聂微东
Vercel News
Vercel News
aimingoo的专栏
aimingoo的专栏
F
Fortinet All Blogs
Microsoft Security Blog
Microsoft Security Blog
MongoDB | Blog
MongoDB | Blog
B
Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
WordPress大学
WordPress大学
Apple Machine Learning Research
Apple Machine Learning Research
阮一峰的网络日志
阮一峰的网络日志
大猫的无限游戏
大猫的无限游戏
GbyAI
GbyAI
Martin Fowler
Martin Fowler
M
MIT News - Artificial intelligence
The GitHub Blog
The GitHub Blog
博客园_首页
博客园 - 叶小钗
腾讯CDC
G
Google Developers Blog
Blog — PlanetScale
Blog — PlanetScale
宝玉的分享
宝玉的分享
D
Docker

博客园 - rangeliu

批判下微软的sql面试题 SQL Server 报表系统导出txt格式方法 Reporting Service报表纵向单元格合并 SSAS中命名集(SET)的使用 返回指定成员所有下级成员的MDX语句 MDX学习——初始MDX [收藏]Oracle 性能优化 [收藏]使用XML技術實現OWC對數據庫的展示 十六進制的字符串轉換為double類型 [收藏]递归算出两个数字之间所有数字之和 [收藏]String与string的区别 [收藏]about协议的妙用 [收藏]中英文颜色对照表 [收藏]C# WinForm程序如何与JS交互 [转载]动态调用WebService(C#) [转载] .NET脏字过滤算法 [转载]使用Response.Filter过滤非法词汇 [转载]asp.net面试集合 [转载]WEB开发碰到的问题及经验十八则
[收藏]在C#程序中使用系统热键
rangeliu · 2009-01-24 · via 博客园 - rangeliu

1.首先引入System.Runtime.InteropServices
using System.Runtime.InteropServices; 

2.在类内部声明两个API函数,它们的位置和类的成员变量等同.

4.在类的构造函数出注册系统热键
示例,下例注册了四个热键:

Code


5.重写WndProc()方法,通过监视系统消息,来调用过程
示例:

Code


5.不用说,我们接下来需要实现ProcessHotkey函数:

Code

很明显接下来分别实现函数DecreseVolumnb(); 和AddVolumnb(); 即可.

6.最后别忘了在程序退出时取消热键的注册

Code

Code
[DllImport("user32.dll")] //申明API函数
public static extern bool RegisterHotKey( 
IntPtr hWnd, 
// handle to window 
int id, // hot key identifier 
uint fsModifiers, // key-modifier options 
Keys vk // virtual-key code 
); 

[DllImport(

"user32.dll")] //申明API函数 
public static extern bool UnregisterHotKey( 
IntPtr hWnd, 
// handle to window 
int id // hot key identifier 
); 


3.定义一个KeyModifiers的枚举,以便出现组合键

Code