标签:
代码:屏蔽三个全局快捷键
代码的作用是屏蔽掉注释中的三个快捷键.
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(); }
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:
原文地址:http://blog.csdn.net/jiangqin115/article/details/47831039