Solved

List all component from a application

Posted on 2006-11-23
6
175 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
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!

 
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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

688 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