delphi2010获取鼠标指向窗口的位置及鼠标在窗口内的相对位置坐标


本文整理自网络,侵删。

  delphi2010获取鼠标指向窗口的位置及鼠标在窗口内的相对位置坐标 unit Unit2;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;

type
TForm2 = class(TForm)
Timer1: TTimer;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form2: TForm2;

implementation

{$R *.dfm}

procedure TForm2.Timer1Timer(Sender: TObject);

var
p: TPoint;
h: HWND;
r:trect;
begin
GetCursorPos(p);
h := WindowFromPoint(p);
GetWindowRect(h,r);//得到窗口的左上角坐标
label4.Caption:=format('x: %d, y: %d',[r.left,r.top]);
Windows.ScreenToClient(h, p);
label1.Caption:=format('x: %d, y: %d',[p.X,p.y]);//鼠标在窗口里的相对位置坐标

end;

end.

相关阅读 >>

Delphi 设计一个有渐变色的标签

Delphi stringgrid之属性大全

Delphi 一行一行读取txt文件

Delphi firemonkey 图片显示拉伸不变形

Delphi 截取字符串的用法

Delphi关闭程序close,application.terminate与halt区别

Delphi 字符串保存utf-8过程

Delphi tparallel并行性能测试

Delphi使用idhttp模拟提交页面方法总结

Delphi dbgrid 表格自适应宽度

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...