日期:2014-05-17 浏览次数:20794 次
#include "hookkey.h" #pragma code_seg("code") HWND phmain = NULL ; HHOOK g_keyhook = NULL ; HHOOK g_mousehook = NULL ; #pragma code_seg() #pragma comment(linker , "/SECTION:code,RWS") BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) { // switch (ul_reason_for_call) // { // case DLL_PROCESS_ATTACH: // case DLL_THREAD_ATTACH: // case DLL_THREAD_DETACH: // case DLL_PROCESS_DETACH: // break; // } return TRUE; } LRESULT CALLBACK KeyboardProc( int code, // hook code WPARAM wParam, // virtual-key code LPARAM lParam // keystroke-message information ) { if (code <0 ||code== HC_NOREMOVE ) { return CallNextHookEx(g_keyhook , code , wParam ,lParam); } if (code & 0x40000000) //消息重复就交给下一个HOOK链 { return CallNextHookEx(g_keyhook , code , wParam , lParam ); } PostMessage( phmain , WM_KEY , wParam , lParam ); return CallNextHookEx(g_keyhook , code , wParam,lParam ); } LRESULT CALLBACK MouseProc( int nCode, // hook code WPARAM wParam, // message identifier LPARAM lParam // mouse coordinates ) { return 1; } HOOKKEY_API void sethook(int instal , HWND mhwnd ) { if (instal == 1) { phmain = mhwnd ; g_keyhook =SetWindowsHookEx(WH_KEYBOARD ,KeyboardProc , GetModuleHandle("hookkey") , 0 ); } else { UnhookWindowsHookEx(g_keyhook); } } HOOKKEY_API void setsss(int instal , HWND mhwnd ) { if (instal == 1) { phmain = mhwnd ; g_mousehook =SetWindowsHookEx(WH_MOUSE ,MouseProc , GetModuleHandle("hookkey") , 0 ); } else { UnhookWindowsHookEx(g_mousehook); } }
char szkey[80]; GetKeyNameText(lParam, szkey , 80); m_code += szkey ; m_code += "\r\n" ; UpdateData(false);