本文整理自网络,侵删。
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}varh: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 xe android 程序切换到后台及从后台切换到前台实现
Delphi 判断时间是否是下午 dateutils.ispm
更多相关阅读请进入《Delphi》频道 >>