Enumerate Windows

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I need to enumerate windows and find the sum of the rect of all the windows
of a specific application. In C++, I use the APIs - 'EnumWindows ,
GetWindowRect and UnionRect to accomplish the same.

How to perform the above in c#? Is PInvoke the only way to do it or Is there
some inherent c# way?
 
HL said:
Hi,

I need to enumerate windows and find the sum of the rect of all the
windows
of a specific application. In C++, I use the APIs - 'EnumWindows ,
GetWindowRect and UnionRect to accomplish the same.

How to perform the above in c#? Is PInvoke the only way to do it or Is
there
some inherent c# way?

Nothing that I know of except to add and remove each form from a collection
manually as they are created and destroyed. You could do this in a base form
and inherit from it. On the other hand EnumWindows does work pretty well in
C#.

Michael
 
HL,

..NET doesn't provide a method for enumerating windows of arbitrary
application in the system. An application can only enumerate its own
windows.
 
Hi Goutsev,

Can you let me know how an application can enumerate its own windows?



Stoitcho Goutsev (100) said:
HL,

..NET doesn't provide a method for enumerating windows of arbitrary
application in the system. An application can only enumerate its own
windows.

--

Stoitcho Goutsev (100) [C# MVP]

HL said:
Hi,

I need to enumerate windows and find the sum of the rect of all the
windows
of a specific application. In C++, I use the APIs - 'EnumWindows ,
GetWindowRect and UnionRect to accomplish the same.

How to perform the above in c#? Is PInvoke the only way to do it or Is
there
some inherent c# way?
 
If it is an MDI application, you can simply enumerate through the
MdiChildren collection.

foreach(Form f in this.MdiChildren)
{
MessageBox.Show(f.Name);
}

--Brendon

HL said:
Hi Goutsev,

Can you let me know how an application can enumerate its own windows?



Stoitcho Goutsev (100) said:
HL,

..NET doesn't provide a method for enumerating windows of arbitrary
application in the system. An application can only enumerate its own
windows.

--

Stoitcho Goutsev (100) [C# MVP]

HL said:
Hi,

I need to enumerate windows and find the sum of the rect of all the
windows
of a specific application. In C++, I use the APIs - 'EnumWindows ,
GetWindowRect and UnionRect to accomplish the same.

How to perform the above in c#? Is PInvoke the only way to do it or Is
there
some inherent c# way?
 
HL,

Each controls (the form is control too) has Controls collection. There you
can get all windows (controls) that are direct children of the control.
Normally applications has one for which is the main form of the application
and you start from there. You need to write probably recursive methods that
enumerates all direct children of the form and then the children of the
children and so on.

If the application is MDI container you should probably start with the
MdiChildren collection and then you can go down to each mdi child's Controls
collection.

--
Stoitcho Goutsev (100) [C# MVP]


HL said:
Hi Goutsev,

Can you let me know how an application can enumerate its own windows?



Stoitcho Goutsev (100) said:
HL,

..NET doesn't provide a method for enumerating windows of arbitrary
application in the system. An application can only enumerate its own
windows.

--

Stoitcho Goutsev (100) [C# MVP]

HL said:
Hi,

I need to enumerate windows and find the sum of the rect of all the
windows
of a specific application. In C++, I use the APIs - 'EnumWindows ,
GetWindowRect and UnionRect to accomplish the same.

How to perform the above in c#? Is PInvoke the only way to do it or Is
there
some inherent c# way?
 
Back
Top