HOOK 底层键盘消息---WH_KEYBOARD_LL
代码:屏蔽三个全局快捷键
代码的作用是屏蔽掉凝视中的三个快捷键.
LRESULT CALLBACK LowLevelKeyboardProc (INT nCode, WPARAM wParam, LPARAM lParam) { // By returning a non-zero value from the hook procedure, the // message does not get passed to the target window KBDLLHOOKSTRUCT *pkbhs = (KBDLLHOOKSTRUCT *)lParam; BOOL bControlKeyDown = 0; HWND hWnd = GetForegroundWindow(); WCHAR szClassName[MAX_PATH] = {0}; ::GetClassName(hWnd, szClassName, MAX_PATH); switch (nCode) { case HC_ACTION: { // Check to see if the CTRL key is pressed bControlKeyDown = GetAsyncKeyState (VK_CONTROL) >> ((sizeof(SHORT) * 8) - 1); //Disable CTRL+ESC if (pkbhs->vkCode == VK_ESCAPE && bControlKeyDown) return 1; //Disable ALT+TAB if (pkbhs->vkCode == VK_TAB && pkbhs->flags & LLKHF_ALTDOWN) return 1; //Disable ALT+ESC if (pkbhs->vkCode == VK_ESCAPE && pkbhs->flags & LLKHF_ALTDOWN) return 1; break; } default: break; } //MessageBoxA(NULL, "aaa", NULL, MB_OK); return 1; } void ChookKeyboardllDlg::OnBnClickedOk() { // TODO: 在此加入控件通知处理程序代码 Hook=(HHOOK)SetWindowsHookEx(WH_KEYBOARD_LL,(HOOKPROC)LowLevelKeyboardProc, theApp.m_hInstance,0); //CDialogEx::OnOK(); } void ChookKeyboardllDlg::OnBnClickedCancel() { // TODO: 在此加入控件通知处理程序代码 if(Hook) { BOOL result = UnhookWindowsHookEx((HHOOK)Hook); // 卸载钩子 if (result) Hook = NULL; } //CDialogEx::OnCancel(); }
posted on 2017-08-14 20:53 gavanwanggw 阅读(341) 评论(0) 编辑 收藏 举报