工具管理---热键使用

以前用的是快捷键,后来发现当程序隐藏在任务托盘的时候,发现快捷键是无法使用的。

此时需要使用热键。

1 void CToolBoxDlg::InitHotkey()
2 {
3     // 这里注册10个热键,ctr + (0 ---9)        
4     for (int i = 0; i < MaxHotKeyNum; i++)
5     {
6         RegisterHotKey(GetSafeHwnd(), MinHotKey + i, MOD_CONTROL, '0' + i);
7     }
8 }
 1 void CToolBoxDlg::OnHotKey(UINT nHotKeyId, UINT nKey1, UINT nKey2)
 2 {
 3     int key = nHotKeyId - MinHotKey;
 4     // 如果按了设定的热键,执行相应的命令    
 5     if (0 <= key && key <= 9)
 6     {
 7         CToolBoxCtr::GetInstance()->RunToolFile(key);
 8     }
 9 
10     CDialog::OnHotKey(nHotKeyId, nKey1, nKey2);
11 }
1 // 程序退出的时候,需要删除注册的热键
2 void CToolBoxDlg::DelHotkey()
3 {
4     for (int i = 0; i < MaxHotKeyNum; i++)
5     {
6         UnregisterHotKey(GetSafeHwnd(), MinHotKey + i);
7     }
8 }

 

posted @ 2014-10-18 20:20  高山百川  阅读(253)  评论(0编辑  收藏  举报