delphi 获取当前鼠标指针位置文本


本文整理自网络,侵删。

 
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    XPManifest1: TXPManifest;
    Button1: TButton;
    Memo1: TMemo;
    Timer1: TTimer;
    Edit1: TEdit;
    procedure Button1Click(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}
var
h:hwnd;

procedure TForm1.Button1Click(Sender: TObject);
begin
    if timer1.Enabled=false then
    begin
    timer1.Enabled:=true;
    form1.Caption:='开始捕获';
    button1.Caption:='停止';
    end
    else
    begin
    timer1.Enabled:=false;
    form1.Caption:='停止捕获';
    button1.Caption:='开始';
    end;
    //memo1.Clear;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
var
  p: array[0..254] of Char;
  point:TPoint;
  hWd :hwnd;
begin
   GetCursorPos(point);  //取当前鼠标指针位置
   hWd := WindowFromPoint(point);   //取当前鼠标指针位置句柄
   //GetWindowText(hWd, lpCaption, 255);  //获取当前鼠标指针位置文本
 {
  if h <> GetForegroundWindow then
  begin
    h := GetForegroundWindow;
    GetWindowText(h, p, 255);
    }
  if h <> hWd then
  begin
    h := hWd;
    GetWindowText(h, p, 255);

    if p <> '' then
    begin
       Memo1.Lines.Add(p);
       Edit1.Text:=p;
    end;

    //Memo1.Lines.Add(p);
  end;
end;

end.

相关阅读 >>

Delphi实现票据精确打印

Delphi中的strpas功能

Delphi xe android 程序切换到后台及从后台切换到前台实现

Delphi 从文件中读取图像类型

Delphi memo 文本列合并

Delphi touchkeyboard1 基本用法

Delphi 判断时间是否是下午 dateutils.ispm

Delphi d10.x 安卓app开发中创建密钥库文件

Delphi实现webservice带身份认证的数据传输

Delphi 移动客户端的路径的安全正确的写法

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



打赏

取消

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

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

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

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

评论

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