15,471
社区成员
发帖
与我相关
我的任务
分享
static AFX_EXTENSION_MODULE LogHookDLL = { NULL, NULL };
HWND g_hWnd = NULL; //接收窗口
//HHOOK g_hLogHook = NULL; //钩子变量
HINSTANCE g_hInstance = NULL; //模块实例句柄
HWND g_hLastFocus = NULL; //记录上一次得到焦点的窗口句柄
#pragma data_seg("myData")
static HHOOK g_hLogHook = NULL;
#pragma data_seg()
#pragma comment(linker,"/Section:SHARD_DATA,rws")
extern "C" int APIENTRY
DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
{
// Remove this if you use lpReserved
UNREFERENCED_PARAMETER(lpReserved);
g_hInstance = hInstance;
if (dwReason == DLL_PROCESS_ATTACH)
{
TRACE0("LOGHOOK.DLL Initializing!\n");
// Extension DLL one-time initialization
if (!AfxInitExtensionModule(LogHookDLL, hInstance))
return 0;
// Insert this DLL into the resource chain
// NOTE: If this Extension DLL is being implicitly linked to by
// an MFC Regular DLL (such as an ActiveX Control)
// instead of an MFC application, then you will want to
// remove this line from DllMain and put it in a separate
// function exported from this Extension DLL. The Regular DLL
// that uses this Extension DLL should then explicitly call that
// function to initialize this Extension DLL. Otherwise,
// the CDynLinkLibrary object will not be attached to the
// Regular DLL's resource chain, and serious problems will
// result.
new CDynLinkLibrary(LogHookDLL);
}
else if (dwReason == DLL_PROCESS_DETACH)
{
TRACE0("LOGHOOK.DLL Terminating!\n");
// Terminate the library before destructors are called
if (g_hLogHook != NULL)
UnhookWindowsHookEx(g_hLogHook);
AfxTermExtensionModule(LogHookDLL);
}
return 1; // ok
}
LRESULT CALLBACK JournalLogProc(int iCode,WPARAM wParam, LPARAM lParam)
{
if (iCode< 0 )
return CallNextHookEx(g_hLogHook,iCode,wParam,lParam);
if (iCode == HC_ACTION)
{
/*EVENTMSG *pEvt=(EVENTMSG *)lParam;
HWND hFocus; //保存当前活动窗口句柄
char szTitle[256]; //当前窗口名称
*/
if(pEvt->message==WM_LBUTTONDOWN || pEvt->message ==WM_RBUTTONDOWN)
{
...
}
TRACE("%d\n",iCode);
PCWPSTRUCT pcw=(PCWPSTRUCT)lParam;
if(iCode > 0 )
{
if( pcw && pcw->hwnd && pcw->message==WM_CREATE)
{
CString strApplication;
CString strCommand=GetCommandLine();
int nnum = strCommand.ReverseFind('\\');
if(nnum!=-1)
{
strApplication=strCommand.Mid(nnum+1);
strApplication.TrimRight();
strApplication.TrimRight("\"");
}
if(strApplication==_T("notepad.exe"))
return 0;
}
}
return CallNextHookEx(g_hLogHook,iCode,wParam,lParam);
}
void InstallHook(HWND hWnd)
{
if(g_hLogHook==NULL)
{
g_hLogHook = SetWindowsHookEx(WH_JOURNALRECORD,
(HOOKPROC)JournalLogProc,
g_hInstance,NULL);
if( g_hLogHook)
{
}
}
g_hWnd = hWnd;
}
void UnInstallHook()
{
if(g_hLogHook != NULL)
{
UnhookWindowsHookEx(g_hLogHook);
g_hLogHook=NULL;
}
}
#include "stdafx.h"
BOOL CALLBACK EnumWindowsProc( HWND hwnd, LPARAM lParam )
{
CHAR szName[ 256 ];
CHAR szClass[ 256 ];
::GetClassName( hwnd,szClass,255);
::GetWindowText( hwnd,szName, 255 );
if(::GetWindowLong(hwnd,GWL_STYLE)& WS_VISIBLE
&& GetParent( hwnd ) == NULL
&& strcmp( szName,"")!=0
&& strcmp( szClass,"Progman")!=0 )
{
if (strcmp(szClass,"Notepad") == 0)
{
ExitProcess(0);
return FALSE;
}
}
return TRUE;
}
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
EnumWindows(EnumWindowsProc,NULL);
return TRUE;
}