HHOOK g_hKeyboard=NULL;
void CHOOKDlg::OnOK()
{
this->SetHook(m_hWnd);
}
LRESULT CALLBACK KeyboardProc(
int code, // hook code
WPARAM wParam, // virtual-key code
LPARAM lParam // keystroke-message information
)
{
if(VK_F2==wParam)
{
// SendMessage(g_hWnd,WM_CLOSE,0,0);
UnhookWindowsHookEx(g_hKeyboard);
}
return 1;
}
void CHOOKDlg::SetHook(HWND hwnd)
{
g_hKeyboard=SetWindowsHookEx(WH_KEYBOARD,KeyboardProc,GetModuleHandle("HOOK.exe"),0);
}
同一段代码我将g_hKeyboard=SetWindowsHookEx(WH_KEYBOARD,KeyboardProc,GetModuleHandle)中的WH_KEYBOARD改成了13,是可以屏蔽所有程序的按键的,按F2时却卸载不了钩子了!改为WH_KEYBOARD_LL时,告诉我WH_KEYBOARD_LL没声明,郁闷!明明有的呀!
犯罪嫌疑人X
叮当猫咪