c++注册热键,卸载热键
//注册热键 hotkeyid1 = GlobalAddAtom(L"hotkey1") - 0xc000; hotkeyid2 = GlobalAddAtom(L"hotkey2") - 0xc000; m_hotkey1.SetHotKey(VK_F1, NULL); m_hotkey2.SetHotKey(VK_F2, NULL); RegisterHotKey(this->m_hWnd, hotkeyid1, NULL, VK_F1); RegisterHotKey(GetSafeHwnd(), hotkeyid2, NULL, VK_F2); RegisterHotKey(GetSafeHwnd(),hotkeyid1,MOD_CONTROL|MOD_ALT,'x' );
void CdmMFCDlg::OnDestroy() { CDialogEx::OnDestroy(); // TODO: 在此处添加消息处理程序代码 //卸载热键 UnregisterHotKey(GetSafeHwnd(), hotkeyid1); UnregisterHotKey(GetSafeHwnd(), hotkeyid2); GlobalDeleteAtom(hotkeyid1); GlobalDeleteAtom(hotkeyid2); }
//热键消息处理 void CdmMFCDlg::OnHotKey(UINT nHotKeyId, UINT nKey1, UINT nKey2) { // TODO: 在此添加消息处理程序代码和/或调用默认值 //按键消息 if (nHotKeyId == hotkeyid1) { MessageBox(L"启动"); ShowWindow(0); } else if (nHotKeyId == hotkeyid2) { MessageBox(L"停止"); ShowWindow(5); } CDialogEx::OnHotKey(nHotKeyId, nKey1, nKey2); }