unit FrmMainU;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls;
const
HookDemo = '
WINHOOK.dll';
const
WM_HOOKCREATE = WM_USER + 1;
type
TFrmMain =
class(TForm)
Panel1: TPanel;
BtnSetHook: TButton;
BtnClearHook: TButton;
procedure BtnSetHookClick(Sender: TObject);
procedure BtnClearHookClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
FHookSet: Boolean;
procedure EnableButtons;
public
end;
var
FrmMain: TFrmMain;
function SetHook(WinHandle: HWND; MsgToSend: integer): boolean;
stdcall;
external HookDemo;
function FreeHook: boolean;
stdcall;
external HookDemo;
implementation
{$R *.DFM}
procedure TFrmMain.EnableButtons;
begin
BtnSetHook.Enabled :=
not FHookSet;
BtnClearHook.Enabled := FHookSet;
end;
procedure TFrmMain.BtnSetHookClick(Sender: TObject);
begin
FHookSet := LongBool(SetHook(
Handle,WM_HOOKCREATE));
EnableButtons;
end;
procedure TFrmMain.BtnClearHookClick(Sender: TObject);
begin
FHookSet := FreeHook;
EnableButtons;
BtnClearHook.Enabled := false;
end;
procedure TFrmMain.FormCreate(Sender: TObject);
begin
EnableButtons;
end;
end.