bagos,
| Код | unit Unit1;
interface
uses Windows, Messages, Classes, Graphics, Forms, StdCtrls, Controls;
type TForm1 = class(TForm) Button1: TButton; Button2: TButton; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); public FHookStarted : Boolean; procedure JMouseHook(var Msg: tagMSG; var Handled: Boolean); end;
procedure SquareDT(Fx, Fy, Lx, Ly: integer);
var Form1: TForm1; JHook: THandle; Fx, Fy, Lx, Ly: integer;
implementation
{$R *.dfm}
function JournalProc(Code, wParam: Integer; var EventStrut: TEventMsg): Integer; stdcall; begin Result := CallNextHookEx(JHook, Code, wParam, Longint(@EventStrut)); if Code < 0 then Exit; if Code = HC_SYSMODALON then Exit; if Code = HC_ACTION then begin if EventStrut.message = WM_LBUTTONDOWN then begin Fx := EventStrut.paramL; Fy := EventStrut.paramH; end; if EventStrut.message = WM_LBUTTONUP then begin Lx := EventStrut.paramL; Ly := EventStrut.paramH; SquareDT(Fx, Fy, Lx, Ly); end; end; end;
procedure SquareDT(Fx, Fy, Lx, Ly: integer); var c: TCanvas; begin c := TCanvas.Create; c.Brush.Color := clRed; c.Pen.Color := clRed; c.Handle := GetDC(GetWindow(GetDesktopWindow, GW_OWNER)); c.Ellipse(Rect(Fx, Fy, Lx, Ly)); c.free; end;
procedure TForm1.Button1Click(Sender: TObject); begin if FHookStarted then begin MessageBox(Application.Handle, PChar('Mouse Hook is already started'), PChar('Error'), MB_OK); Exit; end; JHook := SetWindowsHookEx(WH_JOURNALRECORD, @JournalProc, hInstance, 0);
if JHook > 0 then FHookStarted := True else MessageBox(Application.Handle, PChar('Can not started'), PChar('Error'), MB_OK); end;
procedure TForm1.Button2Click(Sender: TObject); begin FHookStarted := False; UnhookWindowsHookEx(JHook); JHook := 0; end;
procedure TForm1.JMouseHook(var Msg: tagMSG; var Handled: Boolean); begin Handled := False; if (Msg.message = WM_CANCELJOURNAL) and FHookStarted then JHook := SetWindowsHookEx(WH_JOURNALRECORD, @JournalProc, 0, 0); end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction); begin if FHookStarted then UnhookWindowsHookEx(JHook); end;
end.
|
|