In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

- Help others & share knowledge
- Earn cash & points
- Learn & ask questions

4 Comments

this will allow you to draw on the canvas,

function windowsDesktopCanvas: TCanvas;

var

DC: HDc;

begin

DC := getWindowDC ( GetDeskTopWindow );

result := TCanvas.Create;

result.Handle := DC;

end;

try and excute your command now.

cheers

andy

unit Main;

interface

uses

Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,

Math;

type

TForm1 = class(TForm)

procedure FormMouseDown(Sender: TObject; Button: TMouseButton;

Shift: TShiftState; X, Y: Integer);

procedure FormMouseUp(Sender: TObject; Button: TMouseButton;

Shift: TShiftState; X, Y: Integer);

procedure FormPaint(Sender: TObject);

procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X,

Y: Integer);

private

{ Private declarations }

x1,x2,y1,y2: integer;

procedure arrow(x1,y1,x2,y2: integer; sharp,size: integer);

public

{ Public declarations }

end;

var

Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.FormMouseDown(Sende

Shift: TShiftState; X, Y: Integer);

begin

x1 := X;

y1 := Y;

x2 := X;

y2 := Y;

end;

procedure TForm1.FormMouseMove(Sende

Y: Integer);

begin

if ( ssLeft in shift ) then

begin

Canvas.Pen.Color := clWhite;

Canvas.Pen.Style := psSolid;

Canvas.Pen.Mode := pmXor;

Canvas.Pen.width := 1;

Canvas.MoveTo(x1,y1);

Canvas.LineTo(x2,y2);

x2 := X;

y2 := Y;

Canvas.MoveTo(x1,y1);

Canvas.LineTo(x2,y2);

end;

end;

procedure TForm1.FormMouseUp(Sender:

Shift: TShiftState; X, Y: Integer);

begin

x2 := X;

y2 := Y;

Invalidate;

end;

procedure TForm1.FormPaint(Sender: TObject);

begin

inherited;

if ( (x1=x2) and (y1=y2) ) then

exit;

arrow(x1,y1,x2,y2,30,40);

end;

procedure TForm1.arrow(x1,y1,x2,y2: integer; sharp,size: integer);

var

sharprad: single;

angle,len,rise,run: single;

hx,hy: single;

begin

Canvas.Pen.Color := clBlue;

Canvas.Pen.Style := psSolid;

Canvas.Pen.Mode := pmCopy;

Canvas.Pen.width := 1;

Canvas.MoveTo(x1,y1);

Canvas.LineTo(x2,y2);

// convert arrow sharpness to radians.

sharprad := (sharp/360)*(2*pi);

// Determine the "rise" and "run" of the line

rise := -(y2-y1); // use -ve because real world counts from bottom up,

// delphi counts from top down.

run := (x2-x1);

// Determine the length of the line

len := sqrt(rise*rise+run*run);

// Determine the angle (in radians) of the line from horizontal.

angle := arcsin(abs(rise)/len);

if ( run<0 ) then

angle := pi-angle;

if ( rise<0 ) then

angle := 2*pi-angle;

// Determine x,y of arrow's head part 1

hx := -cos(angle+sharprad);

hy := sin(angle+sharprad);

x1 := Round(x2+hx*size);

y1 := Round(y2+hy*size);

// Center point is the end point of the line. (x2,y2)

Canvas.MoveTo(x2,y2);

Canvas.LineTo(x1,y1);

// Determine x,y of arrow's head part 2

hx := -cos(angle-sharprad);

hy := sin(angle-sharprad);

x1 := Round(x2+hx*size);

y1 := Round(y2+hy*size);

// Center point is the end point of the line. (x2,y2)

Canvas.MoveTo(x2,y2);

Canvas.LineTo(x1,y1);

end;

end.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Course of the Month11 days, left to enroll

Join the community of 500,000 technology professionals and ask your questions.