Solved

delphi global cursor position

Posted on 2010-11-17
4
1,038 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
select query - oracle 16 103
JAudiorecorder record freezing the app 29 92
DBCtrlGrid, Delphi, Scroll 7 35
Firemonkey Listview item popup menu ? 1 74
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

739 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