WH_GETMESSAGE钩子

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.

 

你可能感兴趣的:(WH_GETMESSAGE钩子)