VC添加全局热键的方法
VC添加全局热键的方法
这个方法靠谱
http://blog.csdn.net/lujianfeiccie2009/article/details/7498704
![](http://static.blog.csdn.net/images/category_icon.jpg)
版权声明:本文为博主原创文章,未经博主允许不得转载。
全局热键定义 VirtualKey.h
在PreTranslateMessage方法里添加全局热键的事件响应
- /************************************************************************/
- // VirtualKey.H By:lujianfei 2009.08.22
- // 定义热键
- #define IDH_HOT1 4001
- #define IDH_HOT2 4002
- #define IDH_HOT3 4003
- #define IDH_HOT4 4004
- #define IDH_HOT5 4005
- #define IDH_HOT6 4006
- #define IDH_HOT7 4007
- #define IDH_HOT8 4008
- #define IDH_HOT9 4009
- #define IDH_HOT10 4010
- #define IDH_HOT11 4011
- #define IDH_HOT12 4012
在InitialDialog里面注册自定义的热键
- RegisterHotKey(this->GetSafeHwnd(),IDH_HOT1, MOD_CONTROL, 'Q'); //CH$
- RegisterHotKey(this->GetSafeHwnd(),IDH_HOT2, MOD_CONTROL, 'W'); //EN$
- RegisterHotKey(this->GetSafeHwnd(),IDH_HOT3, MOD_CONTROL, 'E'); //BUSINESS1$
- RegisterHotKey(this->GetSafeHwnd(),IDH_HOT4, MOD_CONTROL, 'R'); //BUSINESS2$
- RegisterHotKey(this->GetSafeHwnd(),IDH_HOT5, MOD_CONTROL, 'T'); //BUSINESS3$
- RegisterHotKey(this->GetSafeHwnd(),IDH_HOT6, MOD_CONTROL, 'Y'); //BUSINESS4$
- RegisterHotKey(this->GetSafeHwnd(),IDH_HOT7, MOD_CONTROL, 'U'); //BUSINESS5$
- RegisterHotKey(this->GetSafeHwnd(),IDH_HOT8, MOD_CONTROL, 'I'); //BUSINESS6$
- RegisterHotKey(this->GetSafeHwnd(),IDH_HOT9, MOD_CONTROL, 'O'); //NUM1$
- RegisterHotKey(this->GetSafeHwnd(),IDH_HOT10, MOD_CONTROL, 'P'); //NUM2$
- RegisterHotKey(this->GetSafeHwnd(),IDH_HOT11, MOD_CONTROL, 'A'); //NUM3$
- RegisterHotKey(this->GetSafeHwnd(),IDH_HOT12, MOD_CONTROL, 'S'); //NUM4$
- RegisterHotKey(this->GetSafeHwnd(),IDH_HOT13, MOD_CONTROL, 'D'); //NUM5$
在PreTranslateMessage方法里添加全局热键的事件响应
- BOOL CLedControllerDlg::PreTranslateMessage(MSG* pMsg)
- {// TODO: Add your specialized code here and/or call the base class
- char buffer[20];
- if( WM_HOTKEY == pMsg->message )
- {
- switch(pMsg->wParam)
- {
- case IDH_HOT1:
- strcpy(buffer,"CH$");
- break;
- case IDH_HOT2:
- strcpy(buffer,"EN$");
- break;
- case IDH_HOT3:
- strcpy(buffer,"BUSINESS1$");
- break;
- case IDH_HOT4:
- strcpy(buffer,"BUSINESS2$");
- break;
- case IDH_HOT5:
- strcpy(buffer,"BUSINESS3$");
- break;
- case IDH_HOT6:
- strcpy(buffer,"BUSINESS4$");
- break;
- case IDH_HOT7:
- strcpy(buffer,"BUSINESS5$");
- break;
- case IDH_HOT8:
- strcpy(buffer,"BUSINESS6$");
- break;
- case IDH_HOT9:
- strcpy(buffer,"NUM1$");
- break;
- case IDH_HOT10:
- strcpy(buffer,"NUM2$");
- break;
- case IDH_HOT11:
- strcpy(buffer,"NUM3$");
- break;
- case IDH_HOT12:
- strcpy(buffer,"NUM4$");
- break;
- case IDH_HOT13:
- strcpy(buffer,"NUM5$");
- break;
- }
- }
- return CDialog::PreTranslateMessage(pMsg);
- }
posted on 2017-01-20 07:49 okgogo2000 阅读(591) 评论(0) 编辑 收藏 举报