1

It can be answer in C# or C++ or WinAPI (I know how to pInvoke).

What I want to achieve. I want to get number of windows that are opened by another applicatoin. For example I have Chat application. I want to get number of windows because I wan't to detect if someone send me message (New incoming message = one more window).

So in short. How to get number of windows opened by another process.

Hooch
  • 28,817
  • 29
  • 102
  • 161
  • 1
    An answer involving the WinAPI != An answer in C++. – Puppy May 30 '11 at 10:45
  • @DeadMG This can be in WinAPI. My mistake. – Hooch May 30 '11 at 10:52
  • "New incoming message = one more window": This will backfire badly if the target chat application changes its UI so that only one window is used for all messages. It may be okay if you never change your chat application, but even then it's really a kludge. – In silico May 30 '11 at 10:57
  • @In silico This is only example. I want to use it to other task. But it's easier to explain it on that chat example. – Hooch May 30 '11 at 11:02

2 Answers2

2

If you have the process ID of the other application, here's a possible Windows API way:

Enumerate all top level windows with the EnumWindows function, using GetWindowThreadProcessId in the callback function to test for main windows belonging to your given process. From matching main windows you can then continue to enumerate all its child windows with EnumChildWindows.

TeaWolf
  • 714
  • 5
  • 10
1

First, you need a handle to the top-level window. FindWindow() retrieves it if you know the name of the window.

The second step was already explained a number of times on SO:

.NET (C#): Getting child windows when you only have a process handle or PID?

How can I get the child windows of a window given its HWND?

Community
  • 1
  • 1
karlphillip
  • 92,053
  • 36
  • 243
  • 426