1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| function TForm1.GetCaptionAtPoint(CrPos: TPoint): string;
var
textlength: Integer;
Text: PChar;
Handle: HWND;
begin
Result := 'Empty';
Handle := WindowFromPoint(CrPos);
if Handle = 0 then Exit;
textlength := SendMessage(Handle, WM_GETTEXTLENGTH, 0, 0);
if textlength <> 0 then
begin
getmem(Text, textlength + 1);
SendMessage(Handle, WM_GETTEXT, textlength + 1, Integer(Text));
Result := Text;
freemem(Text);
end;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var SourisPos: TPoint;
begin
GetCursorPos(SourisPos);
Edit1.Text:=GetCaptionAtPoint(SourisPos);
end; |
Partager