http://www.csdn.net/develop/read_article.asp?id=21439
目的想完成屏蔽目标程序的WM_CLOSE事件,结果把监视窗口给屏蔽了!
贴下面写着一些功能要自己实现,从来没用过HOOK,不知道这些实现的代码应该写在何处,请各位帮忙!!!
我的程序代码在FTP://Hwkknd:Hwkknd@bestarit.8800.org
下面的HookDLL.rar
哪位下载帮忙添加一下……
在此鞠躬等候……
解决问题分随便要……
13 个解决方案
#1
有人知吗?
#2
hook在基于超级线程cpu时候
问题太多
建议别用
问题太多
建议别用
#3
如果不用,还有更好的办法可以屏蔽其它程序的WM_CLOSE消息吗?
#4
其中有一个设置消息的过程(据我理解应该是)如下:
procedure HookProc(nCode, wParam, lParam: LongWORD);stdcall;
var
hEvent: THandle;
begin
if not DllData^.SubClass then {如果此窗口未子类化}
begin {保存窗口过程地址并子类化}
if hEvent <> 0 then
begin
WaitForSingleObject(hEvent, INFINITE);
CloseHandle(hEvent);
end;
DLLData^.OldWndProc := pointer(GetWindowLong(DLLData^.HookWindow, GWL_WNDPROC));
SetWindowLong(DLLData^.HookWindow, GWL_WNDPROC, integer(@NewWndProc));
DLLData^.SubClass := True;
hEvent := OpenEvent(Synchronize, False, HOOK_EVENT_NAME);
end;
{调用下一个Hook}
CallNextHookEx(DLLData^.hHook, nCode, wParam, lParam);
end;
如果调用这个过程那其三个参数应该是什么呢??
如果有用到这个过程的话,我想应该就可以了吧……
哪位知道……
procedure HookProc(nCode, wParam, lParam: LongWORD);stdcall;
var
hEvent: THandle;
begin
if not DllData^.SubClass then {如果此窗口未子类化}
begin {保存窗口过程地址并子类化}
if hEvent <> 0 then
begin
WaitForSingleObject(hEvent, INFINITE);
CloseHandle(hEvent);
end;
DLLData^.OldWndProc := pointer(GetWindowLong(DLLData^.HookWindow, GWL_WNDPROC));
SetWindowLong(DLLData^.HookWindow, GWL_WNDPROC, integer(@NewWndProc));
DLLData^.SubClass := True;
hEvent := OpenEvent(Synchronize, False, HOOK_EVENT_NAME);
end;
{调用下一个Hook}
CallNextHookEx(DLLData^.hHook, nCode, wParam, lParam);
end;
如果调用这个过程那其三个参数应该是什么呢??
如果有用到这个过程的话,我想应该就可以了吧……
哪位知道……
#5
伤心的UP
#6
对不起,哪篇贴子怪我没说明白.
HookProc这个函数是HOOK过程,在HOOK上目标进程后由Windows自动调用.
你要监视目标进程,只需要调用这个DLL中引出的InstallHook(目标窗口句柄, 自己的监视窗口句柄);就可以了..
HookProc这个函数是HOOK过程,在HOOK上目标进程后由Windows自动调用.
你要监视目标进程,只需要调用这个DLL中引出的InstallHook(目标窗口句柄, 自己的监视窗口句柄);就可以了..
#7
访问不了你的FTP,如果你还是有问题就发到akunspy@sina.com我帮你改改...
#8
up
#9
谢谢 pankun(剑神一笑 反对日本新干线)
程序我发出去了……
呵……文章是你写的,我从早上研究到现在的……
除了一脑袋汗一无所获……
非常感谢……
我有好久没问问题了…
我会再开贴,所有分都给你……
程序我发出去了……
呵……文章是你写的,我从早上研究到现在的……
除了一脑袋汗一无所获……
非常感谢……
我有好久没问问题了…
我会再开贴,所有分都给你……
#10
呵……还有,那个屏掉监视端是因为我乱写消息造成的!
#11
InstallHook(目标窗口句柄, 自己的监视窗口句柄);
这个我有调用了,但我要在哪个消息里得到WM_CLOSE这个消息呢?
我在DLL工程中跟踪,代码好象没有执行到InstallHook这个里面……
所以把代码发给你,还劳烦你帮忙看一下我的调用是否正确…
我在按下Install后会返回成功的信息,但却接收不到被监视窗体的事件信息…—…
是不是我那种取HANDLE的方法不行……
这个我有调用了,但我要在哪个消息里得到WM_CLOSE这个消息呢?
我在DLL工程中跟踪,代码好象没有执行到InstallHook这个里面……
所以把代码发给你,还劳烦你帮忙看一下我的调用是否正确…
我在按下Install后会返回成功的信息,但却接收不到被监视窗体的事件信息…—…
是不是我那种取HANDLE的方法不行……
#12
可以用内存映射的方法取得HANDLE!看看这个取MOUSE动作的DLL!
library HookDLL;
uses WinTypes, WinProcs, Messages;
type
TGoData = record
TargetWnd : Hwnd;
ghHook : HHook;
end;
PGoData = ^TGoData;
const WM_MOUSE1 = WM_USER+16;
WM_KEYBO = WM_USER+18;
var
GoData : PGoData;
MemFile : THandle;
HookCount: integer;
HookHandle,HOOKHandleb: HHook;
function MouseHookCallBack(Code: integer; Msg: WPARAM; MouseHook: LPARAM): lresult; stdcall;
begin
if Code >= 0 then postmessage(GoData^.TargetWnd ,WM_MOUSE1,msg,0);
// Result := CallNextHookEx(HookHandleb, Code,msg,mousehook);
result:=1;
end;
function KeyboardHookHandler(iCode: Integer;wParam: WPARAM;lParam: LPARAM): LRESULT; stdcall;
begin
If iCode >= 0 Then
begin
postmessage(GoData^.TargetWnd ,WM_KEYBO,WPARAM,LPARAM);
Result := 1;
END
ELSE
Result := CallNextHookEx(HookHandleb, iCode, wParam, lParam);
end;
function InstallHook(TaskHandle: THandle) : boolean; export;
begin
Result := TRUE;
GoData^.TargetWnd := TaskHandle;
if HookCount = 0 then begin
HookHandle := SetWindowsHookEx(WH_MOUSE, @MouseHookCallBack, HInstance, 0);
HookHandleb:= setwindowshookex(WH_KEYBOARD, @KeyboardHookHandler,HInstance,0);
if (HookHandle <> 0 )and (hookhandleb <> 0)then
inc(HookCount)
else
Result := FALSE;
end else
inc(HookCount);
end;
function RemoveHook: boolean; export;
begin
Result := FALSE;
if HookCount < 1 then exit;
Result := TRUE;
dec(HookCount);
if HookCount = 0 then
Result := UnhookWindowsHookEx(HookHandle) and UnhookWindowsHookEx(HookHandleb);
end;
procedure IntoShare; stdcall;export;
begin
MemFile := OpenFileMapping( FILE_MAP_WRITE, False, 'JJYY' );
if MemFile = 0 then
MemFile:=CreateFileMapping( $FFFFFFFF, nil,
PAGE_READWRITE, 0, SizeOf( TGoData ), 'JJYY');
GoData := MapViewOfFile( MemFile, FILE_MAP_WRITE, 0, 0, 0 );
if MemFile = 0 then
FillChar( GoData^, SizeOf( TGoData ),0);
end;
exports
InstallHook,
RemoveHook,
IntoShare,
MouseHookCallBack;
begin
IntoShare;
HookCount := 0;
HookHandle := 0;
hookhandleb := 0;
end.
library HookDLL;
uses WinTypes, WinProcs, Messages;
type
TGoData = record
TargetWnd : Hwnd;
ghHook : HHook;
end;
PGoData = ^TGoData;
const WM_MOUSE1 = WM_USER+16;
WM_KEYBO = WM_USER+18;
var
GoData : PGoData;
MemFile : THandle;
HookCount: integer;
HookHandle,HOOKHandleb: HHook;
function MouseHookCallBack(Code: integer; Msg: WPARAM; MouseHook: LPARAM): lresult; stdcall;
begin
if Code >= 0 then postmessage(GoData^.TargetWnd ,WM_MOUSE1,msg,0);
// Result := CallNextHookEx(HookHandleb, Code,msg,mousehook);
result:=1;
end;
function KeyboardHookHandler(iCode: Integer;wParam: WPARAM;lParam: LPARAM): LRESULT; stdcall;
begin
If iCode >= 0 Then
begin
postmessage(GoData^.TargetWnd ,WM_KEYBO,WPARAM,LPARAM);
Result := 1;
END
ELSE
Result := CallNextHookEx(HookHandleb, iCode, wParam, lParam);
end;
function InstallHook(TaskHandle: THandle) : boolean; export;
begin
Result := TRUE;
GoData^.TargetWnd := TaskHandle;
if HookCount = 0 then begin
HookHandle := SetWindowsHookEx(WH_MOUSE, @MouseHookCallBack, HInstance, 0);
HookHandleb:= setwindowshookex(WH_KEYBOARD, @KeyboardHookHandler,HInstance,0);
if (HookHandle <> 0 )and (hookhandleb <> 0)then
inc(HookCount)
else
Result := FALSE;
end else
inc(HookCount);
end;
function RemoveHook: boolean; export;
begin
Result := FALSE;
if HookCount < 1 then exit;
Result := TRUE;
dec(HookCount);
if HookCount = 0 then
Result := UnhookWindowsHookEx(HookHandle) and UnhookWindowsHookEx(HookHandleb);
end;
procedure IntoShare; stdcall;export;
begin
MemFile := OpenFileMapping( FILE_MAP_WRITE, False, 'JJYY' );
if MemFile = 0 then
MemFile:=CreateFileMapping( $FFFFFFFF, nil,
PAGE_READWRITE, 0, SizeOf( TGoData ), 'JJYY');
GoData := MapViewOfFile( MemFile, FILE_MAP_WRITE, 0, 0, 0 );
if MemFile = 0 then
FillChar( GoData^, SizeOf( TGoData ),0);
end;
exports
InstallHook,
RemoveHook,
IntoShare,
MouseHookCallBack;
begin
IntoShare;
HookCount := 0;
HookHandle := 0;
hookhandleb := 0;
end.
#13
tanxj(明剑)
非常感谢……
非常感谢……
#1
有人知吗?
#2
hook在基于超级线程cpu时候
问题太多
建议别用
问题太多
建议别用
#3
如果不用,还有更好的办法可以屏蔽其它程序的WM_CLOSE消息吗?
#4
其中有一个设置消息的过程(据我理解应该是)如下:
procedure HookProc(nCode, wParam, lParam: LongWORD);stdcall;
var
hEvent: THandle;
begin
if not DllData^.SubClass then {如果此窗口未子类化}
begin {保存窗口过程地址并子类化}
if hEvent <> 0 then
begin
WaitForSingleObject(hEvent, INFINITE);
CloseHandle(hEvent);
end;
DLLData^.OldWndProc := pointer(GetWindowLong(DLLData^.HookWindow, GWL_WNDPROC));
SetWindowLong(DLLData^.HookWindow, GWL_WNDPROC, integer(@NewWndProc));
DLLData^.SubClass := True;
hEvent := OpenEvent(Synchronize, False, HOOK_EVENT_NAME);
end;
{调用下一个Hook}
CallNextHookEx(DLLData^.hHook, nCode, wParam, lParam);
end;
如果调用这个过程那其三个参数应该是什么呢??
如果有用到这个过程的话,我想应该就可以了吧……
哪位知道……
procedure HookProc(nCode, wParam, lParam: LongWORD);stdcall;
var
hEvent: THandle;
begin
if not DllData^.SubClass then {如果此窗口未子类化}
begin {保存窗口过程地址并子类化}
if hEvent <> 0 then
begin
WaitForSingleObject(hEvent, INFINITE);
CloseHandle(hEvent);
end;
DLLData^.OldWndProc := pointer(GetWindowLong(DLLData^.HookWindow, GWL_WNDPROC));
SetWindowLong(DLLData^.HookWindow, GWL_WNDPROC, integer(@NewWndProc));
DLLData^.SubClass := True;
hEvent := OpenEvent(Synchronize, False, HOOK_EVENT_NAME);
end;
{调用下一个Hook}
CallNextHookEx(DLLData^.hHook, nCode, wParam, lParam);
end;
如果调用这个过程那其三个参数应该是什么呢??
如果有用到这个过程的话,我想应该就可以了吧……
哪位知道……
#5
伤心的UP
#6
对不起,哪篇贴子怪我没说明白.
HookProc这个函数是HOOK过程,在HOOK上目标进程后由Windows自动调用.
你要监视目标进程,只需要调用这个DLL中引出的InstallHook(目标窗口句柄, 自己的监视窗口句柄);就可以了..
HookProc这个函数是HOOK过程,在HOOK上目标进程后由Windows自动调用.
你要监视目标进程,只需要调用这个DLL中引出的InstallHook(目标窗口句柄, 自己的监视窗口句柄);就可以了..
#7
访问不了你的FTP,如果你还是有问题就发到akunspy@sina.com我帮你改改...
#8
up
#9
谢谢 pankun(剑神一笑 反对日本新干线)
程序我发出去了……
呵……文章是你写的,我从早上研究到现在的……
除了一脑袋汗一无所获……
非常感谢……
我有好久没问问题了…
我会再开贴,所有分都给你……
程序我发出去了……
呵……文章是你写的,我从早上研究到现在的……
除了一脑袋汗一无所获……
非常感谢……
我有好久没问问题了…
我会再开贴,所有分都给你……
#10
呵……还有,那个屏掉监视端是因为我乱写消息造成的!
#11
InstallHook(目标窗口句柄, 自己的监视窗口句柄);
这个我有调用了,但我要在哪个消息里得到WM_CLOSE这个消息呢?
我在DLL工程中跟踪,代码好象没有执行到InstallHook这个里面……
所以把代码发给你,还劳烦你帮忙看一下我的调用是否正确…
我在按下Install后会返回成功的信息,但却接收不到被监视窗体的事件信息…—…
是不是我那种取HANDLE的方法不行……
这个我有调用了,但我要在哪个消息里得到WM_CLOSE这个消息呢?
我在DLL工程中跟踪,代码好象没有执行到InstallHook这个里面……
所以把代码发给你,还劳烦你帮忙看一下我的调用是否正确…
我在按下Install后会返回成功的信息,但却接收不到被监视窗体的事件信息…—…
是不是我那种取HANDLE的方法不行……
#12
可以用内存映射的方法取得HANDLE!看看这个取MOUSE动作的DLL!
library HookDLL;
uses WinTypes, WinProcs, Messages;
type
TGoData = record
TargetWnd : Hwnd;
ghHook : HHook;
end;
PGoData = ^TGoData;
const WM_MOUSE1 = WM_USER+16;
WM_KEYBO = WM_USER+18;
var
GoData : PGoData;
MemFile : THandle;
HookCount: integer;
HookHandle,HOOKHandleb: HHook;
function MouseHookCallBack(Code: integer; Msg: WPARAM; MouseHook: LPARAM): lresult; stdcall;
begin
if Code >= 0 then postmessage(GoData^.TargetWnd ,WM_MOUSE1,msg,0);
// Result := CallNextHookEx(HookHandleb, Code,msg,mousehook);
result:=1;
end;
function KeyboardHookHandler(iCode: Integer;wParam: WPARAM;lParam: LPARAM): LRESULT; stdcall;
begin
If iCode >= 0 Then
begin
postmessage(GoData^.TargetWnd ,WM_KEYBO,WPARAM,LPARAM);
Result := 1;
END
ELSE
Result := CallNextHookEx(HookHandleb, iCode, wParam, lParam);
end;
function InstallHook(TaskHandle: THandle) : boolean; export;
begin
Result := TRUE;
GoData^.TargetWnd := TaskHandle;
if HookCount = 0 then begin
HookHandle := SetWindowsHookEx(WH_MOUSE, @MouseHookCallBack, HInstance, 0);
HookHandleb:= setwindowshookex(WH_KEYBOARD, @KeyboardHookHandler,HInstance,0);
if (HookHandle <> 0 )and (hookhandleb <> 0)then
inc(HookCount)
else
Result := FALSE;
end else
inc(HookCount);
end;
function RemoveHook: boolean; export;
begin
Result := FALSE;
if HookCount < 1 then exit;
Result := TRUE;
dec(HookCount);
if HookCount = 0 then
Result := UnhookWindowsHookEx(HookHandle) and UnhookWindowsHookEx(HookHandleb);
end;
procedure IntoShare; stdcall;export;
begin
MemFile := OpenFileMapping( FILE_MAP_WRITE, False, 'JJYY' );
if MemFile = 0 then
MemFile:=CreateFileMapping( $FFFFFFFF, nil,
PAGE_READWRITE, 0, SizeOf( TGoData ), 'JJYY');
GoData := MapViewOfFile( MemFile, FILE_MAP_WRITE, 0, 0, 0 );
if MemFile = 0 then
FillChar( GoData^, SizeOf( TGoData ),0);
end;
exports
InstallHook,
RemoveHook,
IntoShare,
MouseHookCallBack;
begin
IntoShare;
HookCount := 0;
HookHandle := 0;
hookhandleb := 0;
end.
library HookDLL;
uses WinTypes, WinProcs, Messages;
type
TGoData = record
TargetWnd : Hwnd;
ghHook : HHook;
end;
PGoData = ^TGoData;
const WM_MOUSE1 = WM_USER+16;
WM_KEYBO = WM_USER+18;
var
GoData : PGoData;
MemFile : THandle;
HookCount: integer;
HookHandle,HOOKHandleb: HHook;
function MouseHookCallBack(Code: integer; Msg: WPARAM; MouseHook: LPARAM): lresult; stdcall;
begin
if Code >= 0 then postmessage(GoData^.TargetWnd ,WM_MOUSE1,msg,0);
// Result := CallNextHookEx(HookHandleb, Code,msg,mousehook);
result:=1;
end;
function KeyboardHookHandler(iCode: Integer;wParam: WPARAM;lParam: LPARAM): LRESULT; stdcall;
begin
If iCode >= 0 Then
begin
postmessage(GoData^.TargetWnd ,WM_KEYBO,WPARAM,LPARAM);
Result := 1;
END
ELSE
Result := CallNextHookEx(HookHandleb, iCode, wParam, lParam);
end;
function InstallHook(TaskHandle: THandle) : boolean; export;
begin
Result := TRUE;
GoData^.TargetWnd := TaskHandle;
if HookCount = 0 then begin
HookHandle := SetWindowsHookEx(WH_MOUSE, @MouseHookCallBack, HInstance, 0);
HookHandleb:= setwindowshookex(WH_KEYBOARD, @KeyboardHookHandler,HInstance,0);
if (HookHandle <> 0 )and (hookhandleb <> 0)then
inc(HookCount)
else
Result := FALSE;
end else
inc(HookCount);
end;
function RemoveHook: boolean; export;
begin
Result := FALSE;
if HookCount < 1 then exit;
Result := TRUE;
dec(HookCount);
if HookCount = 0 then
Result := UnhookWindowsHookEx(HookHandle) and UnhookWindowsHookEx(HookHandleb);
end;
procedure IntoShare; stdcall;export;
begin
MemFile := OpenFileMapping( FILE_MAP_WRITE, False, 'JJYY' );
if MemFile = 0 then
MemFile:=CreateFileMapping( $FFFFFFFF, nil,
PAGE_READWRITE, 0, SizeOf( TGoData ), 'JJYY');
GoData := MapViewOfFile( MemFile, FILE_MAP_WRITE, 0, 0, 0 );
if MemFile = 0 then
FillChar( GoData^, SizeOf( TGoData ),0);
end;
exports
InstallHook,
RemoveHook,
IntoShare,
MouseHookCallBack;
begin
IntoShare;
HookCount := 0;
HookHandle := 0;
hookhandleb := 0;
end.
#13
tanxj(明剑)
非常感谢……
非常感谢……