⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 myfunc.cpp

📁 精通MFC配书盘 为精通MFC一书中所有源代码 好书 好代码 !可以很好地进行 学习
💻 CPP
字号:

#include "stdafx.h"
#include "SAMPLE74_DLL.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

#ifndef _EXPORTING
#define _EXPORTING
#endif
#include "myfunc.h"
//多个进程的共享数据
#pragma data_seg("SHARDATA")
//是否已经初始化
BOOL   gbInited	= FALSE;
//是否已经安装
BOOL   gbInstalled = FALSE;
//安装挂钩的窗口
static HWND	ghwndMain = NULL;		// Main hwnd. We will get this from the App
#pragma data_seg()
//外面定义的全局应用对象
extern CSAMPLE74_DLLApp theApp;
//进程范围的钩子句柄
static HHOOK hHook;

extern "C" void  __stdcall InitHooksDll(HWND hwndMainWindow)
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState());

    ghwndMain = hwndMainWindow;	
    gbInited =  TRUE; 

}

//消息钩子
LRESULT	__stdcall GetMessageFunc (int nCode, WPARAM wParam, LPARAM lParam )
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState());

	MSG *lpMsg;
	if ( nCode >= 0 ) {
	   //取得消息
	  lpMsg = (MSG *) lParam;
	  CString s;
	  s.Format("取得消息 进程句柄:%d 窗口句柄:%d 时间:%d  位置:%d %d 消息标志:%d ",
	       theApp.m_hInstance,lpMsg->hwnd, lpMsg->time,
	       lpMsg->pt.x, lpMsg->pt.y, lpMsg->message
		   );
	
	//TRACE(s);
	  CWnd wnd;
	  wnd.Attach(ghwndMain);
	  CDC* pDC=wnd.GetDC();
	  pDC->TextOut(0,0,s);
	  wnd.Detach();	  
	  //CDC dc;	 
	  //= GetDC(hwndMain);
   }
   //调用下一个钩子
   return CallNextHookEx(hHook, nCode, wParam, lParam);
}
extern "C" BOOL  __stdcall	InstallFilter (BOOL bInstall)
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState());

	if ( ! gbInited )
	 {
		return FALSE;
     }
     if ( bInstall ) 
	 {		
		if(!gbInstalled)
		{
			hHook = SetWindowsHookEx(WH_GETMESSAGE, (HOOKPROC) GetMessageFunc, theApp.m_hInstance,0);
			if(hHook)
			{
				gbInstalled = TRUE;	
			}
		}
     }
     else
	 {
		 if(gbInstalled)
		 {
			if(UnhookWindowsHookEx(hHook))
			{
				gbInstalled = FALSE;
			}
		}		
     }//else

	 return TRUE;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -