hook高手看过来!!!(10分)

  • 主题发起人 主题发起人 tanxj
  • 开始时间 开始时间
T

tanxj

Unregistered / Unconfirmed
GUEST, unregistred user!
我很想知道,在hook中怎样回调主程序,如下:
procedure Ttest.FormCreate(Sender: TObject);
begin
;installhook(true,0);
end;

procedure Ttest.FormClose(Sender: TObject; var Action: TCloseAction);
begin
removehook;
end;

procedure ttest.hookmouse()
begin
;edit1.text:=inttostr(x); edit2.text:=inttostr(y);
end;
//这里怎样定义这个函数才能接收到hook发过的x,y坐标!


另外我的dll如下:

library HookDLL;

uses WinTypes, WinProcs, Messages;

const WM_MOUSE1 = WM_USER+16;
var
; HookCount: integer;
; HookHandle: HHook;
; handle:THANDLE;
; x,y:integer;



function MouseHookCallBack(Code: integer; Msg: WPARAM; MouseHook: LPARAM): LRESULT; stdcall;

function MouseHookCallBack(Code: integer; Msg: word; MouseHook: longint): longint; export;
begin
; if Code >= 0 then begin
; ; if Msg = WM_RBUTTONDOWN then
; ; begin
; ; ; Messagebeep(1);
; ; ; postmessage(x,y.....);//to hookmouse//怎样发送这个点击的坐标到上面的test form?
; ; end
; ; else Result := CallNextHookEx(HookHandle, Code, Msg, MouseHook);
; end else
; ; Result := CallNextHookEx(HookHandle, Code, Msg, MouseHook);
end;

{ Call InstallHook to set the hook. }
function InstallHook(SystemHook: boolean; TaskHandle: THandle) : boolean; export;
begin
; Result := TRUE;
; if HookCount = 0 then begin
; ; if SystemHook then
; ; ; HookHandle := SetWindowsHookEx(WH_MOUSE, MouseHookCallBack, HInstance, 0);
; ; if HookHandle <> 0 then
; ; ; inc(HookCount)
; ; else
; ; ; Result := FALSE;
; end else
; ; inc(HookCount);
end;


function RemoveHook: boolean; export;
begin
; { See if our reference count is down to 0, and if so then unhook. }
; Result := FALSE;
; if HookCount < 1 then exit;
; Result := TRUE;
; dec(HookCount);
; if HookCount = 0 then
; ; Result := UnhookWindowsHookEx(HookHandle);
end;

{ Have we hooked into the system? }
function IsHookSet: boolean; export;
begin
; Result := (HookCount > 0) and (HookHandle <> 0);
end;

exports
; InstallHook,
; RemoveHook,
; IsHookSet,
; MouseHookCallBack;

begin
; HookCount := 0;
; HookHandle := 0;
end.
 
postmessage(TestForm.handle,WM_MOUSE1 ,x,y);这样就可以了。我试过的:)
 
就是hook所得到的消息如何让主程序得知,然后在主程序中根据这一消息再处理其他东西?
我想知道?
 
接受答案了.
 
后退
顶部