转载:http://blog.csdn.net/easysec/article/details/8833457
转载:http://www.vckbase.com/module/articleContent.php?id=567&title=
用VS创建一个空的动态库(dll)工程ShieldScreen
ShieldScreen.h文件
1 #ifndef _SHIELDSCREEN_H_ 2 #define _SHIELDSCREEN_H_ 3 #include <windows.h> 4 5 #ifdef _cplusplus 6 extern "C" 7 { 8 #endif 9 void WINAPI UnInstallLaunchEv();//安装钩子 10 void WINAPI InstallLaunchEv();//去掉钩子 11 #ifdef _cplusplus 12 }; 13 #endif 14 15 #endif
ShieldScreen.cpp文件
1 // ShieldScreen.cpp : Defines the exported functions for the DLL application. 2 // 3 4 #include "stdafx.h" 5 #include <stdio.h> 6 7 HHOOK Hook; 8 9 LRESULT CALLBACK LauncherHook(int nCode, WPARAM wParam, LPARAM lParam); 10 void strerror(DWORD errno); 11 void savelog(const char* s); 12 extern HMODULE hHookDll; 13 14 15 _declspec(dllexport) void WINAPI UnInstallLaunchEv()//dll的导出函数 16 { 17 UnhookWindowsHookEx(Hook); 18 } 19 20 _declspec(dllexport)void WINAPI InstallLaunchEv()//dll的导出函数 21 { 22 Hook = SetWindowsHookEx(WH_KEYBOARD_LL,(HOOKPROC)LauncherHook,hHookDll,0); 23 24 if (Hook == NULL) 25 { 26 strerror(GetLastError()); 27 } 28 } 29 30 LRESULT CALLBACK LauncherHook(int nCode, WPARAM wParam, LPARAM lParam) 31 { 32 KBDLLHOOKSTRUCT *Key_Info = (KBDLLHOOKSTRUCT*)lParam; 33 34 if (nCode == HC_ACTION) 35 { 36 if ( WM_KEYDOWN == wParam || WM_SYSKEYDOWN == wParam ) 37 { 38 BOOL b_lctrl = ::GetAsyncKeyState(VK_LCONTROL) ;//如果左边Ctrl按下 39 BOOL b_rctrl = ::GetAsyncKeyState(VK_RCONTROL) ;//如果右边Ctrl按下 40 BOOL b_lAlt = ::GetAsyncKeyState(VK_LMENU) ;//如果左边Alt按下 41 BOOL b_rAlt = ::GetAsyncKeyState(VK_RMENU) ;//如果右边Alt按下 42 43 if ( Key_Info->vkCode == VK_SNAPSHOT ) 44 { 45 return TRUE; 46 } 47 else if (b_lctrl && b_lAlt) 48 { 49 switch (wParam) 50 { 51 case 41: //('A') 52 break; 53 default: 54 break; 55 } 56 return TRUE; 57 } 58 else if (b_rctrl && b_rAlt) 59 { 60 switch (wParam) 61 { 62 case 41://('A') 63 break; 64 default: 65 break; 66 } 67 return TRUE; 68 } 69 else if (b_lAlt) 70 { 71 switch (wParam) 72 { 73 case 41://('A') 74 break; 75 default: 76 break; 77 } 78 return TRUE; 79 } 80 else if (b_rAlt) 81 { 82 switch (wParam) 83 { 84 case 41://('A') 85 break; 86 default: 87 break; 88 } 89 return TRUE; 90 } 91 } 92 } 93 94 return CallNextHookEx(Hook,nCode,wParam,lParam); 95 } 96 97 98 void savelog(const char* s)//向D盘根目录下的my.log文件写log信息 99 { 100 FILE* p; 101 errno_t err= fopen_s(&p,"D:\my.log", "a+");//在d盘根目录下生成my.log文件 102 fputs(s,p);//fputs是一种函数,具有的功能是向指定的文件写入一个字符串(不自动写入字符串结束标记符‘