#include#pragma comment(lib, "User32.lib")HHOOK g_hKeyboard = NULL;#pragma data_seg("MySec")#pragma data_seg()#pragma comment(linker,"/section:MySec,RWS")HHOOK g_Hook;//此处为钩子过程函数,与方案一中的钩子过程函数相同,不再重复,其中函数名改为KeyboardHookProcLRESULT WINAPI KeyboardHookProc(int nCode,WPARAM wParam,LPARAM lParam){ LPKBDLLHOOKSTRUCT pKB = (LPKBDLLHOOKSTRUCT)lParam; BOOL bKeyToShield = FALSE; if(nCode == HC_ACTION){ switch(wParam){ case WM_KEYDOWN: case WM_SYSKEYDOWN: case WM_KEYUP: case WM_SYSKEYUP:{ bKeyToShield = (pKB->vkCode == VK_LWIN) || (pKB->vkCode == VK_RWIN)|| /* win键*/ (pKB->vkCode == VK_ESCAPE) || (pKB->vkCode == VK_RETURN) || /* esc键*/ ((pKB->vkCode == VK_TAB) && ((pKB->flags & LLKHF_ALTDOWN) != 0))|| /* alt+tab*/ ((pKB->vkCode == VK_ESCAPE) && ((pKB->flags & LLKHF_ALTDOWN) != 0))|| /* alt+esc*/ ((pKB->vkCode == VK_ESCAPE) && ((GetKeyState(VK_CONTROL) & 0x8000) != 0)); /* ctrl+tab*/ break; } default: break; } } return(bKeyToShield?TRUE:CallNextHookEx(g_Hook,nCode,wParam,lParam));}void SetHook()//安装钩子{ g_hKeyboard = SetWindowsHookEx(WH_KEYBOARD_LL, KeyboardHookProc, GetModuleHandle(L"KeyboardHook"), 0); }void UnHook() //卸载钩子{ UnhookWindowsHookEx(g_hKeyboard);}/******************************************dll END******************************************/