L
lujean
Unregistered / Unconfirmed
GUEST, unregistred user!
试着编一个mouse hook程序 , dll中有installhook,removehook,
MouseHookCallBack函数,
function MouseHookCallBack(Code: integer; Msg: WPARAM; MouseHook: LPARAM): LRESULT; stdcall;
var
x,y:integer
begin
if Code >= 0 then begin
if Msg = WM_MOUSEMOVE then begin
x:=Pmousehookstruct(MouseHook)^.pt.x
y:=Pmousehookstruct(MouseHook)^.pt.y
PostMessage(Fhandle,WM_POS,x,y);
messagebeep(0); end
......
在主程序中的Form中
Const WM_POS = WM_USER +1
HOOK_DLL = 'HOOKDLL.DLL';
function InstallHook(SystemHook: boolean;Fhandle : Thandle): boolean; external HOOK_DLL;
// 这里fhandle我传的是form.handle
function RemoveHook: boolean; external HOOK_DLL;
....
procedure DispPos(var mes : Tmessage) message WM_POS
begin
label1.caption := 'x:'+inttostr(mes.wparam ) + 'y:'+inttostr(mes.lparam)
end;
运行后, 发现只有当鼠标在form中移动时, label上才有显示, 当鼠标
移出form, 则label不显示 .为什么? 我建立hook时是建立的全局hook呀.
还有, 为何在dll中的MouseHookCallBack中不能将Mousehook直接
postmessage给form ?当我写成这样时 :
....
function MouseHookCallBack(Code: integer; Msg: WPARAM; MouseHook: LPARAM): LRESULT; stdcall;
begin
if Code >= 0 then begin
if Msg = WM_MOUSEMOVE then begin
PostMessage(Fhandle,WM_POS, 0 , MouseHook );
.....
Form 中:
procedure DispPos(var mes : Tmessage) message WM_POS
begin
with Pmousehookstruct(mes.lparam)^ do
label1.caption := 'x:'+inttostr(pt.x ) + 'y:'+inttostr(pt.y)
end;
这时得到的值不对!!
是不是我无法访问dll中的指针?
请各位大侠出手, 救我于水火!
MouseHookCallBack函数,
function MouseHookCallBack(Code: integer; Msg: WPARAM; MouseHook: LPARAM): LRESULT; stdcall;
var
x,y:integer
begin
if Code >= 0 then begin
if Msg = WM_MOUSEMOVE then begin
x:=Pmousehookstruct(MouseHook)^.pt.x
y:=Pmousehookstruct(MouseHook)^.pt.y
PostMessage(Fhandle,WM_POS,x,y);
messagebeep(0); end
......
在主程序中的Form中
Const WM_POS = WM_USER +1
HOOK_DLL = 'HOOKDLL.DLL';
function InstallHook(SystemHook: boolean;Fhandle : Thandle): boolean; external HOOK_DLL;
// 这里fhandle我传的是form.handle
function RemoveHook: boolean; external HOOK_DLL;
....
procedure DispPos(var mes : Tmessage) message WM_POS
begin
label1.caption := 'x:'+inttostr(mes.wparam ) + 'y:'+inttostr(mes.lparam)
end;
运行后, 发现只有当鼠标在form中移动时, label上才有显示, 当鼠标
移出form, 则label不显示 .为什么? 我建立hook时是建立的全局hook呀.
还有, 为何在dll中的MouseHookCallBack中不能将Mousehook直接
postmessage给form ?当我写成这样时 :
....
function MouseHookCallBack(Code: integer; Msg: WPARAM; MouseHook: LPARAM): LRESULT; stdcall;
begin
if Code >= 0 then begin
if Msg = WM_MOUSEMOVE then begin
PostMessage(Fhandle,WM_POS, 0 , MouseHook );
.....
Form 中:
procedure DispPos(var mes : Tmessage) message WM_POS
begin
with Pmousehookstruct(mes.lparam)^ do
label1.caption := 'x:'+inttostr(pt.x ) + 'y:'+inttostr(pt.y)
end;
这时得到的值不对!!
是不是我无法访问dll中的指针?
请各位大侠出手, 救我于水火!