1、 HOOK编程之屏蔽所有当前线程消息 本帖最后由 lezhen98 于 2009-9-5 11:03 编辑 DLL 文件代码 #include “windows.h“ HWND dlg; HHOOK mouse; HHOOK keyboard; LRESULT CALLBACK KeyboardProc( int code, / hook code WPARAM wParam, / virtual-key code LPARAM lParam / keystroke-message information ) if(VK_F2=wParam)/按 F2 退出 程序 :SendMessage(d
2、lg,WM_CLOSE,0,0);/发送关闭窗口消息 :UnhookWindowsHookEx(keyboard); :UnhookWindowsHookEx(mouse);/卸载键盘和鼠标消息钩子 return 1; LRESULT CALLBACK mouseproc( int code, / hook code WPARAM wParam, / virtual-key code LPARAM lParam / keystroke-message information ) return 1; void sethook(HWND hwnd) dlg=hwnd; /设置消息钩子 keyboa
3、rd=:SetWindowsHookEx(WH_KEYBOARD,KeyboardProc,:GetModuleHandle(“20“),0); mouse=:SetWindowsHookEx(WH_MOUSE,mouseproc,:GetModuleHandle(“20“),0); 源程序代码 #include “windows.h“ #include “resource.h“ BOOL _stdcall leyongwei(HWND,UINT,WPARAM,LPARAM); int _stdcall WinMain(HINSTANCE hInstance,HINSTANCE,LPSTR,i
4、nt) :DialogBoxParam( hInstance, / 实例句柄 (LPCTSTR)IDD_MAIN, / 对话框资源 ID 号 NULL, / 父窗口句柄 leyongwei, / 消息处理函数 NULL); / 对话框初始化 return 0; _declspec(dllimport) void sethook(HWND hwnd);/导入 Dll 文件 BOOL _stdcall leyongwei(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) switch(message) case WM_INITDIALOG
5、: :SetWindowText(hwnd,“屏蔽当前所有线程消息 “); :SetWindowText(:GetDlgItem(hwnd,IDC_EDIT1),“只能按 F2 退出程序 “); :SetWindowPos(hwnd,HWND_TOP,0,0,400,200,SWP_SHOWWINDOW);/设置最顶层窗口 break; case WM_COMMAND: switch(LOWORD(wParam) case IDCANCEL: :EndDialog(hwnd,IDCANCEL); break; case IDC_MOUSE: sethook(hwnd);/设置鼠标消息钩子 break; case IDC_KEYBOARD:/设置键盘消息钩子 sethook(hwnd); break; return 0; http:/