Unit1.pas
Upload User: kukotwo
Upload Date: 2007-01-29
Package Size: 188k
Code Size: 2k
Category:

Hook api

Development Platform:

WINDOWS

  1. unit Unit1;
  2. interface
  3. uses
  4.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  5.   MapFileUnit;
  6. type
  7.   TForm1 = class(TForm)
  8.     procedure FormCreate(Sender: TObject);
  9.     procedure FormClose(Sender: TObject; var Action: TCloseAction);
  10.   private
  11.     { Private declarations }
  12.   public
  13.     { Public declarations }
  14.     procedure WndProc(var Mess: TMessage); override;
  15.   end;
  16. var
  17.   Form1: TForm1;
  18.   ZW_MSG : UINT;
  19.   HMapFile:THandle;
  20.   CommonData:pCommonData;
  21. implementation
  22. {$R *.DFM}
  23. function  EnableMouseHook(hld:hwnd): boolean; stdcall; external 'MHK.dll';
  24. function  DisableMouseHook: boolean; stdcall; external 'MHK.dll';
  25. procedure TForm1.WndProc(var Mess: TMessage);
  26. begin
  27.   if (mess.msg = ZW_MSG) then
  28.   begin
  29.     caption := 's';
  30.     if CommonData<>nil then with CommonData^ do
  31.           Caption := Format('Mouse Pos: %d, Y : %d',
  32.                                         [MousePos.X,
  33.                                          MousePos.Y]);
  34.   end;
  35.   inherited;
  36. end;
  37. procedure TForm1.FormCreate(Sender: TObject);
  38. begin
  39.   ZW_MSG := RegisterWindowMessage('WM_ZWNOTIFY');
  40.   //CommonData := nil;
  41.   MapCommonData(CommonData,HMapFile);
  42.   if not(EnableMouseHook(handle)) then ShowMessage('Enable Mouse Hook failed.');
  43. end;
  44. procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
  45. begin
  46.   if not(DisableMouseHook) then ShowMessage('Disable Mouse Hook failed.');
  47.   if CommonData<>nil then UnMapCommonData(CommonData,HMapFile);
  48. end;
  49. end.
  50.