1. Computing

Get text from the control at pos x,y on screen

From , former About.com Guide

This form has 3 labels and a timer component:

~~~~~~~~~~~~~~~~~~~~~~~~~
unit unit1;

interface

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

type
   TForm1 = class(TForm)
     Timer1: TTimer;
     Label1: TLabel;
     Label2: TLabel;
     Label3: TLabel;
     procedure FormCreate(Sender: TObject) ;
     procedure Timer1Timer(Sender: TObject) ;
   private
   procedure ShowHwndAndClassName(CrPos: TPoint) ;
   public
   end;

var
   Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.ShowHwndAndClassName(CrPos: TPoint) ;
var
   hWnd: THandle;
   aName,
   Text : array [0..255] of char;
begin
   hWnd := WindowFromPoint(CrPos) ;
   Label1.Caption := 'Handle : ' + IntToStr(hWnd) ;

   if boolean(GetClassName(hWnd, aName, 256)) then
     Label2.Caption := 'ClassName : ' + string(aName)
   else
     Label2.Caption := 'ClassName : not found';
   SendMessage(hWnd, WM_GETTEXT,
               SizeOf(Text), integer(@Text)) ;
   Label3.Caption := 'Text :' + Text;
end;

procedure TForm1.FormCreate(Sender: TObject) ;
begin
   Form1.FormStyle := fsStayOnTop;
   Timer1.Interval := 50;
end;

procedure TForm1.Timer1Timer(Sender: TObject) ;
var
   rPos: TPoint;
begin
   if boolean(GetCursorPos(rPos))
   then ShowHwndAndClassName(rPos) ;
end;
end.
~~~~~~~~~~~~~~~~~~~~~~~~~

Delphi tips navigator:
» Add columns to a ListBox
« Activate Windows "Start" button from code

©2013 About.com. All rights reserved.