Fog Creek Software
Discussion Board




Delphi 4 getting mouse coordinates on the screen

I need to get mouse coordinates NOT ONLY on the main form, but on the desktop (screen). Is it possible to do this?
I need a function or procedure something like  this :
procedure Form1.ONMOUSEMOVE.......
but the difference is so, that I need to get the cursor coordinates not on the application (main form)...
Can someone help me?

Mr.Donatas
Wednesday, November 20, 2002

Mr. Donatas,

This little example code should do the trick...

procedure TForm1.FormMouseMove(Sender: TObject;
                              Shift: TShiftState;
                              X,Y: Integer);

var MyPoint : TPoint;

begin
  Label1.Caption:=IntToStr(X);
  Label2.Caption:=IntToStr(Y); // X, Y  on the form.
  GetCursorPos(MyPoint);
  Label3.Caption:=IntToStr(MyPoint.X);
  Label4.Caption:=IntToStr(MyPoint.Y);  X, Y on screen
end;

Have fun,

Patrik
Wednesday, November 20, 2002

Look at ClientToScreen

jt
Thursday, November 21, 2002

*  Recent Topics

*  Fog Creek Home