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.
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.
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?
精彩评论