delphi向另一程序窗口某处发送鼠标事件所用的工具
2011-02-28 23:53
706 查看
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;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Label8: TLabel;
Label9: TLabel;
Label10: TLabel;
Label11: TLabel;
Label12: TLabel;
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
selectr:trect; //注意这里定义为保存选定窗体的左上角
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
procedure TForm2.Timer1Timer(Sender: TObject);
var
p: TPoint;
h: HWND;
r:trect;
begin
GetCursorPos(p);
label6.Caption:=format('x: %d, y: %d',[p.x,p.y]); //鼠标在屏幕绝对位置
h := WindowFromPoint(p);
GetWindowRect(h,r);//得到窗口的左上角坐标
if GetAsyncKeyState(VK_LButton)<>0 then //按下鼠标左键,记下所选的窗体左上角
begin
selectr:=r;
label11.Caption:=format('x: %d, y: %d',[r.left,r.top]);
end;
label4.Caption:=format('x: %d, y: %d',[r.left,r.top]); //当前鼠标位置窗体的左上角
label8.Caption:=format('x: %d, y: %d',[p.x-selectr.left,p.y-selectr.top]);
//label8内为发送鼠标事件所用数据
Windows.ScreenToClient(h, p);
label1.Caption:=format('x: %d, y: %d',[p.X,p.y]);//鼠标在窗口里的相对位置坐标
end;
end.
http://cy03wqh.blog.163.com/blog/static/3678030220108592514544/
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;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Label8: TLabel;
Label9: TLabel;
Label10: TLabel;
Label11: TLabel;
Label12: TLabel;
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
selectr:trect; //注意这里定义为保存选定窗体的左上角
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
procedure TForm2.Timer1Timer(Sender: TObject);
var
p: TPoint;
h: HWND;
r:trect;
begin
GetCursorPos(p);
label6.Caption:=format('x: %d, y: %d',[p.x,p.y]); //鼠标在屏幕绝对位置
h := WindowFromPoint(p);
GetWindowRect(h,r);//得到窗口的左上角坐标
if GetAsyncKeyState(VK_LButton)<>0 then //按下鼠标左键,记下所选的窗体左上角
begin
selectr:=r;
label11.Caption:=format('x: %d, y: %d',[r.left,r.top]);
end;
label4.Caption:=format('x: %d, y: %d',[r.left,r.top]); //当前鼠标位置窗体的左上角
label8.Caption:=format('x: %d, y: %d',[p.x-selectr.left,p.y-selectr.top]);
//label8内为发送鼠标事件所用数据
Windows.ScreenToClient(h, p);
label1.Caption:=format('x: %d, y: %d',[p.X,p.y]);//鼠标在窗口里的相对位置坐标
end;
end.
http://cy03wqh.blog.163.com/blog/static/3678030220108592514544/
相关文章推荐
- delphi2010 向另一个窗口发送鼠标点击事件
- Java程序中取消窗口标题栏以及边框,并使窗口可以相应鼠标事件,被鼠标拖动;设置JFrame背景色
- mfc窗口位置设置,隐藏功能,给其他程序发送虚拟鼠标键盘消息
- 使用mouse_event模拟鼠标事件时,程序窗口失去焦点就失效
- delphi 发送鼠标点击消息到指定窗口
- C语言控制台窗口图形界面编程(八):鼠标事件
- 怎样用delphi编写一个在线发送邮件的程序
- delphi 所有程序运行调试都出现cpu窗口,急!
- 鼠标悬停、事件触发试用,及信号发送
- 微信小程序开发工具调试界面鼠标看不见
- MFC文档(SDI)应用:画图程序(画圆、画线、鼠标事件)
- windows之鼠标穿透窗口事件
- Go版GTK:鼠标事件应用—窗口移动
- opencv用鼠标在窗口中画方形的程序
- C++获取程序窗口外的鼠标坐标
- Java简单图形编辑器 放置、移动和擦除方块 鼠标事件测试程序 Java核心技术 事件处理
- [python] 1、python鼠标点击、移动事件应用——写一个自动下载百度音乐的程序
- 为Delphi程序添加事件和事件处理器
- Delphi 获取外部程序句柄与发送消息
- Node监听鼠标键盘事件,定时发消息小程序,解决robotjs不支持输入汉字问题!