• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Delphi - 通过WinAPI GetCursorPos实现鼠标位置的实时显示

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

通过WinAPI GetCursorPos实现鼠标位置的实时显示

有时候我们需要将鼠标的位置实时抓取出来,可以通过如下方式实现。

添加一个Timer控件,执行间隔改为100ms,双击控件输入如下代码:

1 var
2   P: TPoint;
3 begin
4    GetCursorPos(P);
5    RzLabel_Point.Caption := Format('(%d,%d)', [P.X,P.Y]);
6 end;

在窗体Show事件中输入如下代码,调整下鼠标显示样式:

1 Screen.Cursor := crHandPoint;

最终效果:

 

 

单元代码如下:

 1 unit U_Operation;
 2 
 3 interface
 4 
 5 uses
 6   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
 7   Dialogs, ExtCtrls, RzPanel, StdCtrls, RzLabel;
 8 
 9 type
10   TFrm_Operation = class(TForm)
11     RzGroupBox1: TRzGroupBox;
12     RzGroupBox2: TRzGroupBox;
13     Timer_Display: TTimer;
14     RzLabel1: TRzLabel;
15     RzLabel_Point: TRzLabel;
16     procedure Timer_DisplayTimer(Sender: TObject);
17     procedure FormCreate(Sender: TObject);
18   private
19     { Private declarations }
20   public
21     { Public declarations }
22   end;
23 
24 var
25   Frm_Operation: TFrm_Operation;
26 
27 implementation
28 
29 {$R *.dfm}
30 
31 procedure TFrm_Operation.Timer_DisplayTimer(Sender: TObject);
32 var
33   P: TPoint;
34 begin
35    GetCursorPos(P);
36    RzLabel_Point.Caption := Format('(%d,%d)', [P.X,P.Y]);
37 end;
38 
39 procedure TFrm_Operation.FormCreate(Sender: TObject);
40 begin
41    Screen.Cursor := crHandPoint;
42 end;
43 
44 end.

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
MATLAB例子研究Motion-BasedMultipleObjectTracking发布时间:2022-07-18
下一篇:
Matlab命令汇总发布时间:2022-07-18
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap