Forum Discussion
Sariali
13 years agoContributor
i have the same problem to evaluate the windows classname and caption out of a virtual machine from a operation system we have not installed on a computer where test complete can be run.
so i wrote a little tool in delphi for my own need. hope will help you too.
the form hast simply a tmemo control and a timer.
the source code :
so i wrote a little tool in delphi for my own need. hope will help you too.
the form hast simply a tmemo control and a timer.
the source code :
unit Unit1;
interface
uses
Windows, Classes, Graphics, Forms, StdCtrls, SysUtils, ExtCtrls, Controls, Dialogs,
Buttons, Menus, ComCtrls, DB;
type
TForm1 = class(TForm)
Timer1: TTimer;
Memo1: TMemo;
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
pold : TPoint;
private
function ToTheTop(cwin: THandle): string;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function GetWinCaption(Handle: THandle): string;
var
Len: LongInt;
Title: string;
begin
Result := '';
if Handle = 0 then Exit;
Len := GetWindowTextLength(Handle) + 1;
SetLength(Title, Len);
GetWindowText(Handle, PChar(Title), Len);
Result := TrimRight(Title);
end;
function GetWinClassName(Handle: THandle): string;
var
aName: array[0..255] of char;
begin
Result := '';
if Boolean(GetClassName(Handle, aName, 256)) then
Result := aName
else
Result := '<none>';
end;
function TForm1.ToTheTop(cwin: THandle): string;
var wwnd: THandle;
clsName, winCaption: string;
begin
Result := '';
while cwin <> 0 do
begin
clsName := GetWinClassName(wwnd);
winCaption := GetWinCaption(wwnd);
Result := clsName + '("' +winCaption +'").' + Result ;
wwnd := GetParent(cwin);
if wwnd = 0 then break;
cwin := wwnd;
end;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var
p : TPoint;
x,y : Integer;
h, h1 : Thandle;
begin
Application.ProcessMessages;
GetCursorPos(p);
x := p.x;
y := p.y;
if (pold.x = x) and (pold.y = y) then Exit;
pold.x := x;
pold.y := y;
h := WindowFromPoint(p);
h1 := ChildWindowFromPoint(h,p);
If h1 <> 0 then
h := h1;
memo1.Clear;
memo1.Lines.Add('Handle : ' + IntToStr(h));
memo1.Lines.Add('Name: '+ToTheTop(h));
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
FormStyle := fsStayOnTop;
pold.X := -1;
pold.Y := -1;
Timer1.Interval := 250;
Timer1.Enabled := True;
end;
end.
[\code]
Related Content
- 4 years agoMadGrb