zoukankan      html  css  js  c++  java
  • Hook编程2:全局钩子

    // The following ifdef block is the standard way of creating macros which make exporting 
    // from a DLL simpler. All files within this DLL are compiled with the HOOK_EXPORTS
    // symbol defined on the command line. this symbol should not be defined on any project
    // that uses this DLL. This way any other project whose source files include this file see 
    // HOOK_API functions as being imported from a DLL, wheras this DLL sees symbols
    // defined with this macro as being exported.
    #ifdef HOOK_EXPORTS
    #define HOOK_API __declspec(dllexport)
    #else
    #define HOOK_API __declspec(dllimport)
    #endif
    
    extern HHOOK g_hHook;
    extern HHOOK g_hHookKey;
    extern HINSTANCE g_hIns;
    HOOK_API void SetHook();
    

      

    // Hook.cpp : Defines the entry point for the DLL application.
    //
    
    #include "stdafx.h"
    #include "Hook.h"
    
    HHOOK g_hHook;
    HHOOK g_hHookKey;
    HINSTANCE g_hIns;
    
    BOOL APIENTRY DllMain( HANDLE hModule, 
                           DWORD  ul_reason_for_call, 
                           LPVOID lpReserved
    					 )
    {
    	g_hIns =(HINSTANCE) hModule;
    //     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 MouseProc(
    						   int nCode,      // hook code
    						   WPARAM wParam,  // message identifier
    						   LPARAM lParam   // mouse coordinates
    						   )
    {
    	return 1;
    }
    
    
    LRESULT CALLBACK KeyProc(
    						   int nCode,      // hook code
    						   WPARAM wParam,  // message identifier
    						   LPARAM lParam   // mouse coordinates
    						   )
    {
    	if(wParam == VK_F2){
    		UnhookWindowsHookEx(g_hHook);
    		UnhookWindowsHookEx(g_hHookKey);
    		MessageBox(0,"去掉了Hook","提示",0);
    		return 1;
    	}
    	else return CallNextHookEx(g_hHookKey,nCode,wParam,lParam);	
    }
    
    HOOK_API void SetHook()
    {
    	g_hHook = SetWindowsHookEx(WH_MOUSE,MouseProc,g_hIns,0);
    	g_hHookKey = SetWindowsHookEx(WH_KEYBOARD,KeyProc,g_hIns,0);
    }
    

      

  • 相关阅读:
    Java 添加、验证PDF 数字签名
    Java 将PDF 转为Word、图片、SVG、XPS、Html、PDF/A
    Java 读取PDF中的文本和图片
    Java 将Word转为PDF、PNG、SVG、RTF、XPS、TXT、XML
    Java 添加、读取、删除PPT文档属性
    Java 添加、修改PPT幻灯片中的表格
    Java 转PPT为图片、PDF、SVG、XPS、ODP以及PPT和PPTX互转
    Java 添加Word脚注、尾注
    Java 添加Word目录的2种方法
    Java 添加Word页眉、页脚
  • 原文地址:https://www.cnblogs.com/wucg/p/2429865.html
Copyright © 2011-2022 走看看