[英]C#, C++ , WinAPI - Get Number of windows from another process
It can be answer in C# or C++ or WinAPI (I know how to pInvoke).它可以在 C# 或 C++ 或 WinAPI 中回答(我知道如何 pInvoke)。
What I want to achieve.我想要达到的目标。 I want to get number of windows that are opened by another applicatoin.
我想获取由另一个应用程序打开的 windows 的数量。 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).
我想获取 windows 的号码,因为我不想检测是否有人向我发送消息(新传入消息 = 多一个窗口)。
So in short.所以简而言之。 How to get number of windows opened by another process.
如何获取另一个进程打开的 windows 的编号。
If you have the process ID of the other application, here's a possible Windows API way:如果您有其他应用程序的进程 ID,这里有一个可能的 Windows API 方式:
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. 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 .
从匹配主 windows 然后您可以继续枚举其所有子 windows 与EnumChildWindows 。
First, you need a handle to the top-level window.首先,您需要顶级 window 的句柄。 FindWindow() retrieves it if you know the name of the window.
如果您知道 window 的名称,则FindWindow()会检索它。
The second step was already explained a number of times on SO:第二步已经在 SO 上解释过很多次了:
.NET (C#): Getting child windows when you only have a process handle or PID? .NET (C#):当你只有一个进程句柄或 PID 时得到子 windows?
How can I get the child windows of a window given its HWND? 鉴于其 HWND,如何获得 window 的子 windows?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.