本文整理自网络,侵删。
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 选择目录对话框(selectdirectory 函数)
Delphi 字符串中末位是双字节字符的处理(避免最后一位为乱码)
Delphi webbrowser1 execwb 复制 新建 打开
Delphi里的compile和build都能产生可执行文件,有什么区别啊?
更多相关阅读请进入《Delphi》频道 >>