开发开发

软件的生命
随笔 - 18, 文章 - 0, 评论 - 0, 引用 - 0
数据加载中……

WH_GETMESSAGE钩子


unit Unit1;
interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;
const
  MYMESSAGE=WM_USER+2000;
type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  *******
    { Private declarations }
  public
    { Public declarations }
  end;
var
  Form1: TForm1;
implementation
{$R *.dfm}
var
  hookHandle:HHOOK;
procedure TForm1.Button1Click(Sender: TObject);
begin
  PostMessage(self.Handle,MYMESSAGE,0,0);
end;
function getMsgProc(code:integer;wParam:WPARAM;lParam:LPARAM)
  :Longint;stdcall;
begin
   if (Code = HC_ACTION) then
    if PMsg(lParam)^.Message = MYMESSAGE then
    begin
      showMessage('已经截获该消息');
    end;
    Result := CallNextHookEx(hookHandle, Code, WParam, Longint(@lParam));
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
  hookHandle:=SetWindowsHookEx(WH_GETMESSAGE,
    getMsgProc,HInstance,GetCurrentThreadId);
end;
end.

 

posted on 2011-09-23 20:35 wm6run 阅读(1841) 评论(0)  编辑  收藏