chrislock
asked on
delphi global cursor position
Hi,
I'm trying to understand the code below (which I found on the web).
Its quite simple - a small stayontop form with a Tapplicationevents component and one label.
It works OK but the global mouse position is constantly being refreshed. I've tried to select only mouse messages to reduce the flickering caused by the the vast number of messages/sec, but the app stops working. If the mouse is stationary, the position is still refreshed. Is there anything I can do about this.
Thanks
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, AppEvnts, ExtCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
ApplicationEvents1: TApplicationEvents;
procedure ApplicationEvents1Idle(Sen der: TObject; var Done: Boolean);
procedure ApplicationEvents1Message( var Msg: tagMSG;
var Handled: Boolean);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.ApplicationEvents1I dle(Sender : TObject;
var Done: Boolean);
var
Msg: tagMSG;
Begin
label1.Caption := ' X-' + inttostr(Msg.pt.X) + ' Y-'+ inttostr(Msg.pt.Y);
end;
procedure TForm1.ApplicationEvents1M essage(var Msg: tagMSG; var Handled: Boolean);
begin
label1.Caption := ' X-' + inttostr(Msg.pt.X) + ' Y-'+ inttostr(Msg.pt.Y);
end;
end.
I'm trying to understand the code below (which I found on the web).
Its quite simple - a small stayontop form with a Tapplicationevents component and one label.
It works OK but the global mouse position is constantly being refreshed. I've tried to select only mouse messages to reduce the flickering caused by the the vast number of messages/sec, but the app stops working. If the mouse is stationary, the position is still refreshed. Is there anything I can do about this.
Thanks
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, AppEvnts, ExtCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
ApplicationEvents1: TApplicationEvents;
procedure ApplicationEvents1Idle(Sen
procedure ApplicationEvents1Message(
var Handled: Boolean);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.ApplicationEvents1I
var Done: Boolean);
var
Msg: tagMSG;
Begin
label1.Caption := ' X-' + inttostr(Msg.pt.X) + ' Y-'+ inttostr(Msg.pt.Y);
end;
procedure TForm1.ApplicationEvents1M
begin
label1.Caption := ' X-' + inttostr(Msg.pt.X) + ' Y-'+ inttostr(Msg.pt.Y);
end;
end.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I've been stupid - I thought the getcursorpos proc was limited to the Delphi form!
What a lot of time I've wasted!
I've placed this code in a timer event and it works fine - thanks!
What a lot of time I've wasted!
I've placed this code in a timer event and it works fine - thanks!
You can place that code in a timer with 50 ms interval.
That code is from:
http://home.x-pack.org/delphi-extact-the-cursor-position-and-how-to-set-the-cursorpos/
That code is from:
http://home.x-pack.org/delphi-extact-the-cursor-position-and-how-to-set-the-cursorpos/
If the mouse is not moving (as in idle), there is no need to change/report it.