Hook(钩子),截获系统消息,具体不太会用.
解决方案 »
- 奇怪的SQL语句
- rst的一个String字段,存诸最大字节数是多少?与结构有关吗》
- 关于打包
- 80分,高难度!如何控制其它程序执行指定的操作?(进来看看,更详细说明)
- Inet1.Execute运行需要引用什么控件
- 高分:如何把一个任意类型的文件读取出来后,保存到一个字符类型变量中?
- VB 调用存储过程返回错误和返回数据的问题(分多!)
- VBA编程急救
- ……大出血!!!!!
- Err.Raise Number:=intErr , Number:=intErr是什么意思?
- 救急呀!估计很简单的问题,我本来想把一幅图像放到PICTURE中,不小心放到Form1中的!如何删去呀?
- 关于DataGrid的问题
用vb没法实现,因为vb无法写出来标准动态库
用VC(Not MFC)做一个标准的动态库
使用setWindowsHook将其投到系统进程中
调用hook里的函数时需要返回一个自定义消息,
以供自己开发的应用程序使用
在hook程序里对消息进行处理就可以了,当截获到
需要的消息时,就向自己的程序发自定义消息即可
//#include "stdafx.h"
#include "rtahook.h"
#pragma data_seg("Shared")
UINT WM_MM_FILECLOSE=RegisterWindowMessage("WM_MM_FILECLOSE");
HWND hWndMain = NULL;
HHOOK hHook = NULL;
HWND ghw=NULL;
DWORD pId=NULL;
DWORD tId=NULL;
char WndText[256];
#pragma data_seg()
#pragma comment (linker,"/SECTION:Shared,rws")
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved )
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
// This is an example of an exported variable
RTAHOOK_API int nRtahook=0;
LRESULT CALLBACK CallWndProc( int nCode,
WPARAM wParam,
LPARAM lParam)
{ CWPSTRUCT *lp;
lp=(CWPSTRUCT*) lParam;
if (lp->message==WM_DESTROY)
{
if (lp->hwnd==ghw)
{
long Ret=UnhookWindowsHookEx(hHook);
if (Ret==0)
{
::MessageBox(0,"取消Hook没有成功",NULL,NULL);
return 1;
}
else
{
if (hWndMain==0)
{
MessageBox(0,"主窗体不见了",NULL,NULL);
}
else
{
::SendNotifyMessage(hWndMain,WM_MM_FILECLOSE,0,0);
if (WM_MM_FILECLOSE==0)
MessageBox(0,"自定义消息为空",NULL,NULL);
}
}
}
}
return(CallNextHookEx(hHook,nCode,wParam,lParam));
}
// This is an example of an exported function.
#pragma comment (linker,"/export:HOOK=_HOOK@8")
extern "C" RTAHOOK_API int _stdcall HOOK (LPCTSTR strWndText,LPARAM lParam)
{
lParam=WM_MM_FILECLOSE;
if (lParam=0)
MessageBox(0,"自定义消息没有生成",NULL,NULL);
hWndMain=FindWindow(NULL,strWndText);
if (hWndMain==0)
MessageBox(0,"主窗体没有发现",NULL,NULL);
HINSTANCE hInst = GetModuleHandle("SSHook.dll");
POINT pt;
pt.x=100;
pt.y=100;
ghw=WindowFromPoint(pt);
tId=GetWindowThreadProcessId(ghw,&pId);
hHook=SetWindowsHookEx(WH_CALLWNDPROC,CallWndProc,hInst,tId);
if (hHook==0)
::MessageBox(0,"添加没有成功",NULL,NULL);
//lpPrevWndProc =(WNDPROC) SetWindowLong(ghw, GWL_WNDPROC, (long) WindowProc);
::CloseHandle(hInst);
return WM_MM_FILECLOSE;
}// This is the constructor of a class that has been exported.
// see rtahook.h for the class definition
CRtahook::CRtahook()
{
return;
}