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 选择目录对话框(selectdirectory 函数)

Delphi 之 工具栏组件(ttoolbar)

Delphi 字符串中末位是双字节字符的处理(避免最后一位为乱码)

Delphi webbrowser1 execwb 复制 新建 打开

Delphi源码简单的实现粘贴复制代码

Delphi opendialog文件多选

Delphi 服务端日志记录

Delphi里的compile和build都能产生可执行文件,有什么区别啊?

Delphi savedialog覆盖询问

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



打赏

取消

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

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

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

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

评论

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