Solved

List all component from a application

Posted on 2006-11-23
6
174 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Simple Delphi Question 9 105
CheckListBox usage 3 81
Typecasting TBytes to Integer in Delphi XE8 2 36
Get monday of current week where a week always starts on monday 2 20
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

733 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