delphi 获取当前鼠标指针位置文本  
官方Delphi 学习QQ群: 682628230(三千人)
频道

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.


推荐分享
图文皆来源于网络,内容仅做公益性分享,版权归原作者所有,如有侵权请告知删除!
 

Copyright © 2014 DelphiW.com 开发 源码 文档 技巧 All Rights Reserved
晋ICP备14006235号-8 晋公网安备 14108102000087号

执行时间: 0.043801069259644 seconds