By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,996 Members | 1,051 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,996 IT Pros & Developers. It's quick & easy.

Enumerate Windows

P: n/a
HL
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?
Nov 21 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
"HL" <HL@discussions.microsoft.com> wrote in message
news:6E**********************************@microsof t.com...
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
Nov 21 '05 #2

P: n/a
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" <HL@discussions.microsoft.com> wrote in message
news:6E**********************************@microsof t.com...
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?

Nov 21 '05 #3

P: n/a
HL
Hi Goutsev,

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

"Stoitcho Goutsev (100) [C# MVP]" wrote:
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" <HL@discussions.microsoft.com> wrote in message
news:6E**********************************@microsof t.com...
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?


Nov 23 '05 #4

P: n/a
B
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" <HL@discussions.microsoft.com> wrote in message
news:65**********************************@microsof t.com...
Hi Goutsev,

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

"Stoitcho Goutsev (100) [C# MVP]" wrote:
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" <HL@discussions.microsoft.com> wrote in message
news:6E**********************************@microsof t.com...
> 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?


Nov 23 '05 #5

P: n/a
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" <HL@discussions.microsoft.com> wrote in message
news:65**********************************@microsof t.com...
Hi Goutsev,

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

"Stoitcho Goutsev (100) [C# MVP]" wrote:
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" <HL@discussions.microsoft.com> wrote in message
news:6E**********************************@microsof t.com...
> 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?


Nov 23 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.