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.

4
  • 1
    An answer involving the WinAPI != An answer in C++. Commented May 30, 2011 at 10:45
  • @DeadMG This can be in WinAPI. My mistake. Commented May 30, 2011 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. Commented May 30, 2011 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. Commented May 30, 2011 at 11:02

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

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?

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.