VC添加全局热键的方法

 

 

VC添加全局热键的方法

这个方法靠谱

 

http://blog.csdn.net/lujianfeiccie2009/article/details/7498704

 

VC添加全局热键的方法

标签: bufferclass
 分类:
 
全局热键定义 VirtualKey.h 
[cpp] view plain copy
 
  1. /************************************************************************/  
  2. // VirtualKey.H     By:lujianfei    2009.08.22  
  3. // 定义热键  
  4. #define IDH_HOT1        4001  
  5. #define IDH_HOT2        4002  
  6. #define IDH_HOT3        4003  
  7. #define IDH_HOT4        4004  
  8. #define IDH_HOT5        4005  
  9. #define IDH_HOT6        4006  
  10. #define IDH_HOT7        4007  
  11. #define IDH_HOT8        4008  
  12. #define IDH_HOT9        4009  
  13. #define IDH_HOT10       4010  
  14. #define IDH_HOT11       4011  
  15. #define IDH_HOT12       4012  

 

在InitialDialog里面注册自定义的热键

 

[cpp] view plain copy
 
  1. RegisterHotKey(this->GetSafeHwnd(),IDH_HOT1, MOD_CONTROL, 'Q'); //CH$  
  2.     RegisterHotKey(this->GetSafeHwnd(),IDH_HOT2, MOD_CONTROL, 'W'); //EN$  
  3.     RegisterHotKey(this->GetSafeHwnd(),IDH_HOT3, MOD_CONTROL, 'E'); //BUSINESS1$  
  4.     RegisterHotKey(this->GetSafeHwnd(),IDH_HOT4, MOD_CONTROL, 'R'); //BUSINESS2$  
  5.     RegisterHotKey(this->GetSafeHwnd(),IDH_HOT5, MOD_CONTROL, 'T'); //BUSINESS3$  
  6.     RegisterHotKey(this->GetSafeHwnd(),IDH_HOT6, MOD_CONTROL, 'Y'); //BUSINESS4$  
  7.     RegisterHotKey(this->GetSafeHwnd(),IDH_HOT7, MOD_CONTROL, 'U'); //BUSINESS5$  
  8.     RegisterHotKey(this->GetSafeHwnd(),IDH_HOT8, MOD_CONTROL, 'I'); //BUSINESS6$  
  9.     RegisterHotKey(this->GetSafeHwnd(),IDH_HOT9, MOD_CONTROL, 'O'); //NUM1$  
  10.     RegisterHotKey(this->GetSafeHwnd(),IDH_HOT10, MOD_CONTROL, 'P'); //NUM2$  
  11.     RegisterHotKey(this->GetSafeHwnd(),IDH_HOT11, MOD_CONTROL, 'A'); //NUM3$  
  12.     RegisterHotKey(this->GetSafeHwnd(),IDH_HOT12, MOD_CONTROL, 'S'); //NUM4$  
  13.     RegisterHotKey(this->GetSafeHwnd(),IDH_HOT13, MOD_CONTROL, 'D'); //NUM5$  

在PreTranslateMessage方法里添加全局热键的事件响应

 

 

[cpp] view plain copy
 
  1. BOOL CLedControllerDlg::PreTranslateMessage(MSG* pMsg)   
  2. {// TODO: Add your specialized code here and/or call the base class  
  3.     char buffer[20];  
  4.     if( WM_HOTKEY == pMsg->message )  
  5.     {  
  6.         switch(pMsg->wParam)  
  7.         {  
  8.         case IDH_HOT1:  
  9.             strcpy(buffer,"CH$");  
  10.             break;  
  11.         case IDH_HOT2:  
  12.             strcpy(buffer,"EN$");  
  13.             break;  
  14.         case IDH_HOT3:  
  15.             strcpy(buffer,"BUSINESS1$");  
  16.             break;  
  17.         case IDH_HOT4:  
  18.             strcpy(buffer,"BUSINESS2$");  
  19.             break;  
  20.         case IDH_HOT5:  
  21.             strcpy(buffer,"BUSINESS3$");  
  22.             break;  
  23.         case IDH_HOT6:  
  24.             strcpy(buffer,"BUSINESS4$");  
  25.             break;  
  26.         case IDH_HOT7:  
  27.             strcpy(buffer,"BUSINESS5$");  
  28.             break;  
  29.         case IDH_HOT8:  
  30.             strcpy(buffer,"BUSINESS6$");  
  31.             break;  
  32.         case IDH_HOT9:  
  33.             strcpy(buffer,"NUM1$");  
  34.             break;  
  35.         case IDH_HOT10:  
  36.             strcpy(buffer,"NUM2$");  
  37.             break;  
  38.         case IDH_HOT11:  
  39.             strcpy(buffer,"NUM3$");  
  40.             break;  
  41.         case IDH_HOT12:  
  42.             strcpy(buffer,"NUM4$");  
  43.             break;  
  44.         case IDH_HOT13:  
  45.             strcpy(buffer,"NUM5$");  
  46.             break;  
  47.         }  
  48.     }  
  49.     return CDialog::PreTranslateMessage(pMsg);  
  50. }  

posted on 2017-01-20 07:49  okgogo2000  阅读(591)  评论(0编辑  收藏  举报