Solved

List all component from a application

Posted on 2006-11-23
6
172 Views
Last Modified: 2012-05-05
Hello guys,

I find the window now I need to get all components from it, a list, is there any way?

I did this:

var
  h : thandle;
begin
  h := findwindow('Babylon',nil);
  If h = 0 Then Abort;

end


0
Comment
Question by:hidrau
6 Comments
 
LVL 28

Expert Comment

by:TName
ID: 18004762
Hi, you could try something like this:  (get the parent window, find and list the children - or click on a button)

function EnumChildProc( ph: PCardinal; lParam:Integer):Boolean;
var
h:HWND;
len:Integer;
p:PChar;
begin
 h:=ph^;
 len:=Succ(GetWindowTextLength(h));
 p:=AllocMem(len);
 GetWindowText(h,p,len);
 if len>1 then begin
    Form1.Memo1.Lines.Add(p);  // add child window captions/texts etc to memo
    //if p='Button1' then      //or use these 2 lines to press a button with the caption 'Button1'
      //SendMessage(h, BM_CLICK, 0, 0);
 end;
 result:=true;
end;

procedure TForm1.Button1Click(Sender: TObject);
var hnd: THandle;
begin
  hnd := FindWindow(nil, 'TestApp'); // or 'Babylon' ...
  //if hnd<>0 then
  if IsWindow(hnd) then
        EnumChildWindows(hnd,@EnumChildProc,0);
end;
0
 
LVL 11

Expert Comment

by:calinutz
ID: 18006604
To enumerate all the components on a form:

var
  i:integer;
begin
for i := 0 to componentcount-1 do
log.Memo1.Lines.Add(components[i].Name);
end;
0
 
LVL 1

Author Comment

by:hidrau
ID: 18006951
to list all component from my form I know.

But this didn't work with babylon :((

Could you make a test with babylon Tname?

Thnsk
0
ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

 
LVL 16

Accepted Solution

by:
CodedK earned 500 total points
ID: 18012574
Hi.

Add a TreeView and a Button in your Form.
~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-

unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    TreeView1: TTreeView;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  List : TStringList;
implementation

{$R *.dfm}

type
  EnumClass = class
  public
    Treeview: TTreeview;
    ParentNode: TTreeNode;
  end;
//--------------------------------------------------

function MainEnumProc(Hwnd, lParam: Longint): Boolean; stdcall;
var
  EC: EnumClass;
  ECChild: EnumClass;
  NewNode: TTreeNode;
  Buffer: PChar;
  RtnLen: Longint;
  NodeCaption, Caption, ClassName: string;
begin
  {Get the EnumClass Passed in}

  EC := ENumClass(lParam);
  {Allocate a buffer length}
  {Allocate a string buffer (PChar)}
  Buffer := StrAlloc(501);
  try
    {First get the caption/Text of the window were currently looking at}
    RtnLen := GetWindowText(Hwnd, Buffer, 500);
    Caption := Copy(Buffer, 1, RtnLen);
    {Now get the class name of the window were currently looking at}
    RtnLen := GetClassName(Hwnd, Buffer, 500);
    ClassName := Copy(Buffer, 1, RtnLen);
    {Set the caption of the new node}
    NodeCaption := Format('HWND: %d | ClassName: "%s" | Caption: "%s"', [HWND, ClassName, Caption]);
    {Creat the new node}

    if (List.IndexOfObject(TObject(HWnd)) < 0) then begin // Test for duplicate handles
    List.AddObject('found', TObject(HWnd));
    NewNode := EC.Treeview.Items.AddChild(EC.ParentNode, NodeCaption);
    {The following is for looking at children of this window
    this basically makes the function recursive}
    ECChild := EnumClass.Create;
    try
      ECChild.Treeview := EC.Treeview;
      ECChild.ParentNode := NewNode;
      {Call this function again :) }
      EnumChildWindows(Hwnd, @MainEnumProc, Longint(ECChild));
    finally
      ECChild.Free;
    end;
    end;
  finally
    {Free the buffer we created at the beginning of
    the procedure}
    StrDispose(Buffer);
  end;
  {Return True this will tell windows to
  carry on passing us the information}
  Result := True;
end;

//--------------------------------------------------


procedure TForm1.Button1Click(Sender: TObject);
var
  EC: EnumClass;
  TN: TTreeNode;
  wnd: HWND;

begin
  wnd := findwindow(nil,'Calculator');
  If wnd = 0 Then Abort;
  List := TStringlist.Create;

  {Stop the flockering}
  LockWindowUpdate(TreeView1.Handle);
  try
    {Clear all the items out of the treeview}
    TreeView1.Items.Clear;
    {Create a node which will be the parent}
    TN := TreeView1.Items.Add(nil, 'Window List');
    {Create our own EnumClass.  This will be used as the
    lParam of the EnumWindows Function and will contain
    a TreeView and Parent Node}
    EC := EnumClass.Create;
    try
      EC.Treeview := TreeView1;
      EC.ParentNode := TN;
      {Call the API with the ENumclass}
      if EnumChildWindows(wnd, @MainEnumProc, Longint(EC)) then
        TN.Expand(False);
    finally
      {Ensure we free the object when were done with it}
      EC.Free;
    end;
  finally
    LockWindowUpdate(0);
    List.Free;
  end;
end;

end.
~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-

Hope this helps :)
0
 
LVL 16

Expert Comment

by:CodedK
ID: 18018145
Thanks.
0
 
LVL 1

Author Comment

by:hidrau
ID: 18018155
you're welcome
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Intraweb submit form as a POST request 4 304
Comparing dates in Delphi. Greater than/ Less than 3 154
When I am typing into a TEdit last word repeats 7 134
select query - oracle 16 100
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question