?
Solved

List all component from a application

Posted on 2006-11-23
6
Medium Priority
?
176 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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

765 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