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 idhttp的基本用法

Delphi 使用 tedgebrowser 组件

Delphi 中的md5实现方法及Delphi2009和Delphi2010中用法

Delphi idhttp控件:get/post 请求

Delphi'控件的相对坐标与屏幕坐标转换

Delphi xe并行编程:ttask

Delphi 清除字符串两边空格或指定字符

winapi 字符及字符串函数(3): charupper - 字符或字符串转大写

Delphi 十进制十六进制转换

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



打赏

取消

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

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

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

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

评论

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