Solved

List taskbar child windows

Posted on 2007-03-20
3
318 Views
Last Modified: 2012-06-21
Hi Experts,

I want to list all the processes that show a windows form in taskbar.

Here is my last coding:

public static List<CustomProcess> GetTaskbarWindowsList()
        {
            List<CustomProcess> list = new List<CustomProcess>();
            foreach (System.Diagnostics.Process p in System.Diagnostics.Process.GetProcesses())
            {
                if (!p.MainWindowHandle.Equals(IntPtr.Zero))
                {
                    if (p.MainWindowTitle != string.Empty)
                        list.Add(new CustomProcess(p.Handle, p.MainWindowTitle,p.MainModule.FileName));
                }
            }
            return list;
        }

It returns the main window of a process, but if an app has several sub windows I can't get them: I only get the main window (for example, I only get main  window of Outlook Express (1  result) ,but in taskbar I can see 2 other windows : inbox window, newMessage window).
How can I get those child windows ?
I try EnumChildWindows, but I get all objects in the form, not only the child window handle.

Thanks in advance for your help.
0
Comment
Question by:noulouk
[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
  • 2
3 Comments
 
LVL 21

Expert Comment

by:theGhost_k8
ID: 18762564
hi, i don't have enough resources to try this things.
i have a delphi code which can give u the idea as what it has used is APIs only.
so better you check for the code, and understand the usage of APIs.
0
 
LVL 21

Accepted Solution

by:
theGhost_k8 earned 500 total points
ID: 18762567
hi, i don't have enough resources to try this things.
i have a delphi code which can give u the idea as what it has used is APIs only.
so better you check for the code, and understand the usage of APIs.
here is the answer from a gr8 X-pert, Ferruccio68....:

enumerating childwindows means this...
you start from the topmost parent and look for all children...
'a' is the parent, 'b' the child of 'a' and c is a child of 'b', but also a child of 'a'...
so you must add a check to prevent this double adding....

look how your code is modified...(it's all the unit, no addition to the form)...

unit Unit1;

interface

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

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

var
  Form1: TForm1;
  sl: TStrings;  //object for the double hwnd check
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 (SL.IndexOfObject(TObject(HWnd)) < 0) then begin // Test for duplicate handles
    SL.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
  sl := TStringlist.Create;
  { Get Window under cursor }Sleep(3000);
  wnd := WindowFromPoint(Mouse.CursorPos);

  {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);
    sl.Free;
  end;
end;


end.

I get this from :
http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_20845865.html?sfQueryTermInfo=1+childwindow+list+window
0
 
LVL 9

Author Comment

by:noulouk
ID: 18774868
Delphi is chineese for me, but I try to find how the code filters only windows and I can't get it.
Sorry.
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
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…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

690 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