How can I draw over the desktop window to draw a circle animation on user clicks...
I already trying the code below, launching a Thread to draw the animation...
The code below works, but has some paint problems:
unit UMouseEmphasizer;
interface
implementation
uses
Classes, Windows, Messages, Graphics, Forms;
type
TEmphasizePointDrawer = class(TThread)
private
fPoint: TPoint;
fCanvas: TCanvas;
protected
procedure Execute; override;
public
constructor Create(pt: TPoint); reintroduce;
destructor Destroy; override;
end;
constructor TEmphasizePointDrawer.Create(pt: TPoint);
begin
fPoint := pt;
fCanvas := TCanvas.Create;
fCanvas.Handle := GetDCEx(0, 0, DCX_PARENTCLIP);
inherited Create(True);
FreeOnTerminate := True;
Resume;
end;
destructor TEmphasizePointDrawer.Destroy;
begin
ReleaseDC(0, fCanvas.Handle);
fCanvas.Free;
inherited;
end;
procedure TEmphasizePointDrawer.Execute;
const
INFLATE_DELTA = 10;
var
i: integer;
r: TRect;
begin
r := rect(0,0,0,0);
with fCanvas do
begin
Brush.Style := bsClear;
Pen.Style := psSolid;
Pen.Color := clRed;
Pen.Width := 2;
for i := 0 to 2 do
begin
r := rect(
fPoint.X - (i * INFLATE_DELTA),
fPoint.Y - (i * INFLATE_DELTA),
fPoint.X + (i * INFLATE_DELTA),
fPoint.Y + (i * INFLATE_DELTA)
);
Ellipse(r);
sleep(100);
end;
end;
InflateRect(r, 2, 2);
RedrawWindow(0, @R, 0, RDW_INVALIDATE or RDW_UPDATENOW or RDW_ALLCHILDREN);
end;
function MouseHookHandler(nCode: Integer; MsgID: WParam; Data: LParam): LResult; stdcall;
var
pt: TPoint;
begin
Result := 0;
if nCode < 0 then
Exit;
pt := PMouseHookStruct(Data)^.pt;
case MsgID of
WM_LBUTTONUP:
TEmphasizePointDrawer.Create(pt);
end;
end;
var
gHook: HHOOK=0;
procedure HookMouse; stdcall;
begin
gHook := SetWindowsHookEx(WH_MOUSE, MouseHookHandler, HINSTANCE, 0);
end;
procedure UnhookMouse;
begin
UnhookWindowsHookEx(gHook);
gHook := 0;
end;
initialization
HookMouse;
finalization
UnhookMouse;
end.