dephi的,不知对你有没有用。
unit hookunit;
interface
uses windows,messages,Dialogs,SysUtils;
var hNextHookProc:HHOOK;
kkk:integer;
function ManageThemessage(ncode:integer;Wpara:WPARAM;var lpara:TMSG):LRESULT;stdcall export;
function sethookintowindow:BOOL;export;
function unsethookoutwindow:BOOL;export;implementationfunction sethookintowindow:BOOL;export;begin Result := False;
if hNextHookProc <> 0 then Exit; hNextHookProc := SetWindowsHookEx( WH_GETMESSAGE ,
@ManageThemessage,
HInstance,
0);
Result := hNextHookProc <> 0;
end;function unsethookoutwindow:BOOL;export;
begin
if hNextHookProc <> 0 then
begin
UnhookWindowshookEx(hNextHookProc);
hNextHookProc := 0;
MessageBeep(0);
MessageBeep(0);
end;
Result := hNextHookProc = 0;
end;function ManageThemessage(ncode:integer;Wpara:WPARAM;var lpara:TMSG):LRESULT;stdcall export;
var buf:pchar;
CN:pchar;
h:Thandle;
P:Tpoint;
begin
if lpara.message=WM_RBUTTONDOWN then
begin
getcursorpos(p);
h:=WindowFromPoint(P);
getmem(CN,GetWindowTextLength(h)+1);
GetWindowText(h,CN,GetWindowTextLength(h)+1);
//showmessage(CN);
freemem(CN);
lpara.message:=0;
Result := CallNextHookEx(hNextHookProc, nCode, wPara, longint(@lPara));
exit;
end;
Result := CallNextHookEx(hNextHookProc, nCode, wPara, longint(@lPara));
{ if lpara.message=WM_RBUTTONDOWN then
begin
showmessage('fuck');
lpara.message:=0;
Result := CallNextHookEx(hNextHookProc, nCode, wPara, longint(@lPara));
exit;
end else
if lpara.message=WM_LBUTTONUP then
begin
getmem(buf,254);
getwindowtext(lpara.hwnd,buf,254);
// showmessage(string(buf));
if string(buf)='MsoDockTop' then
begin
lpara.message:=0;
end;
Result := CallNextHookEx(hNextHookProc, nCode, wPara, longint(@lPara));
exit;
end else
begin
getmem(buf,254);
getwindowtext(lpara.hwnd,buf,254);
// showmessage(string(buf));
if string(buf)='MsoDockTop' then
begin
// showmessage(inttostr(lpara.message));
lpara.message:=0;
end;
Result := CallNextHookEx(hNextHookProc, nCode, wPara, Longint(@lpara));
end;}//example
end;end.
unit hookunit;
interface
uses windows,messages,Dialogs,SysUtils;
var hNextHookProc:HHOOK;
kkk:integer;
function ManageThemessage(ncode:integer;Wpara:WPARAM;var lpara:TMSG):LRESULT;stdcall export;
function sethookintowindow:BOOL;export;
function unsethookoutwindow:BOOL;export;implementationfunction sethookintowindow:BOOL;export;begin Result := False;
if hNextHookProc <> 0 then Exit; hNextHookProc := SetWindowsHookEx( WH_GETMESSAGE ,
@ManageThemessage,
HInstance,
0);
Result := hNextHookProc <> 0;
end;function unsethookoutwindow:BOOL;export;
begin
if hNextHookProc <> 0 then
begin
UnhookWindowshookEx(hNextHookProc);
hNextHookProc := 0;
MessageBeep(0);
MessageBeep(0);
end;
Result := hNextHookProc = 0;
end;function ManageThemessage(ncode:integer;Wpara:WPARAM;var lpara:TMSG):LRESULT;stdcall export;
var buf:pchar;
CN:pchar;
h:Thandle;
P:Tpoint;
begin
if lpara.message=WM_RBUTTONDOWN then
begin
getcursorpos(p);
h:=WindowFromPoint(P);
getmem(CN,GetWindowTextLength(h)+1);
GetWindowText(h,CN,GetWindowTextLength(h)+1);
//showmessage(CN);
freemem(CN);
lpara.message:=0;
Result := CallNextHookEx(hNextHookProc, nCode, wPara, longint(@lPara));
exit;
end;
Result := CallNextHookEx(hNextHookProc, nCode, wPara, longint(@lPara));
{ if lpara.message=WM_RBUTTONDOWN then
begin
showmessage('fuck');
lpara.message:=0;
Result := CallNextHookEx(hNextHookProc, nCode, wPara, longint(@lPara));
exit;
end else
if lpara.message=WM_LBUTTONUP then
begin
getmem(buf,254);
getwindowtext(lpara.hwnd,buf,254);
// showmessage(string(buf));
if string(buf)='MsoDockTop' then
begin
lpara.message:=0;
end;
Result := CallNextHookEx(hNextHookProc, nCode, wPara, longint(@lPara));
exit;
end else
begin
getmem(buf,254);
getwindowtext(lpara.hwnd,buf,254);
// showmessage(string(buf));
if string(buf)='MsoDockTop' then
begin
// showmessage(inttostr(lpara.message));
lpara.message:=0;
end;
Result := CallNextHookEx(hNextHookProc, nCode, wPara, Longint(@lpara));
end;}//example
end;end.
解决方案 »
- 软件公司征名
- 点击按钮为何只捕获按钮的WM_LBUTTONUP消息而没有WM_LBUTTONDOWN呢
- 在Win2K中,怎么样判断共享文夹里边的文件被哪些正被哪些用户在使用?
- 哪位知道DevExpress系列有没有教程???
- activeform 怎么发布?客户端能自动注册
- 透明效果!
- office的颜色会随系统颜色的改变而改变,比如用windows xp的蓝色主题,office xp的 memu就是一套蓝色的方案,如果用橄榄色,office xp就
- TeamSource的使用问题
- 为什么当调用鼠标Hook时,帝国时代会退出?
- 还是关于任务拦
- 为什么编译器不认识TControl.caption?????
- 我初次到DELPHI论坛,请各位高手给点建议。。。
uses
windows, messages, hookproc in 'hookproc.pas';
exports
setkeyhook,
endkeyhook;
begin
nexthookproc:=0;
procsaveexit:=exitproc;
exitproc:=@keyhookexit;
end.2.在hookproc.pas中实现了钩子具体过程:
unit hookproc;
interface
uses
windows, messages, sysutils, controls, stdctrls;
var
nexthookproc:hhook;
procsaveexit:pointer;
function keyboardhook(icode:integer;wparam:wparam;
lparam:lparam):lresult;stdcall;export;
function setkeyhook:bool;export;//加载钩子
function endkeyhook:bool;export;//卸载钩子
procedure keyhookexit;far;
const
afilename='c:\debug.txt';//将键盘输入动作写入文件中
var
debugfile:textfile;
implementation
function keyboardhookhandler(icode:integer;wparam:wparam;
lparam:lparam):lresult;stdcall;export;
begin
if icode<0 then
begin
result:=callnexthookex(hnexthookproc,icode,wparam,lparam);
exit;
end;
assignfile(debugfile,afilename);
append(debugfile);
if getkeystate(vk_return)<0 then
begin
writeln(debugfile,'');
write(debugfile,char(wparam));
end
else
write(debugfile,char(wparam));
closefile(debugfile);
result:=0;
end;
function endkeyhook:bool;export;
begin
if nexthookproc<>0 then begin
unhookwindowshookex(nexthookproc);
nexthookproc:=0;
messagebeep(0); end;
result:=hnexthookproc=0;
end;
procedure keyhookexit;far;
begin
if nexthookproc<>0 then endkeyhook;
exitproc:=procsaveexit; end;
end.
我想要的是能替换内存api函数的例子