Solved

List taskbar child windows

Posted on 2007-03-20
3
308 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
  • 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
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…

809 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