Solved

delphi global cursor position

Posted on 2010-11-17
4
1,058 Views
Last Modified: 2012-05-10
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(Sender: 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.ApplicationEvents1Idle(Sender: TObject;
  var Done: Boolean);

var
Msg: tagMSG;
Begin
label1.Caption := ' X-' + inttostr(Msg.pt.X) + ' Y-'+ inttostr(Msg.pt.Y);
end;


procedure TForm1.ApplicationEvents1Message(var Msg: tagMSG; var Handled: Boolean);
begin
label1.Caption := ' X-' + inttostr(Msg.pt.X) + ' Y-'+ inttostr(Msg.pt.Y);
end;
end.
0
Comment
Question by:chrislock
[X]
Welcome to Experts Exchange

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
  • 2
4 Comments
 
LVL 24

Accepted Solution

by:
jimyX earned 500 total points
ID: 34157527
If you are trying to get the global mouse position then use this instead:


var
pt:tpoint;
begin
getcursorpos(pt);
label1.Caption := 'The cursor pos. is: x='+inttostr(pt.x)+' y='+inttostr(pt.y);
end;

Open in new window

0
 
LVL 58

Expert Comment

by:cyberkiwi
ID: 34157610
You may be getting too many messages because of the Idle event. Remove it and see what happens.
If the mouse is not moving (as in idle), there is no need to change/report it.
0
 

Author Closing Comment

by:chrislock
ID: 34157640
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!
0
 
LVL 24

Expert Comment

by:jimyX
ID: 34157641
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/
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses
Course of the Month10 days, 9 hours left to enroll

628 members asked questions and received personalized solutions in the past 7 days.

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

Join & Ask a Question