During the development of windows application, you can operate other windows by enumerating windows with
The original link is 使用 EnumWindows 找到满足你要求的窗口 - walterlv. But this blog was written in Chinese, so I translate its content to English. Waterlv is an MVP(Microsoft Most Valuable Professional), and he is good at .NET Core\WPF\.NET. Here is his Blog.
You can get more details about
EnumWindows from the Microsoft website.
Before you use
C# , you have to write a platform to call the P/Invoke method.
This is the official document for this API description,
Enumerates all top-level windows on the screen by passing the handle to each window, in turn, to an application-defined callback function.
But not all the enumerated windows are top-level windows, some windows are not top-level windows.For more details,visit EnumWindows remarks.
So,we can get all windows by running these codes followed,
public static IReadOnlyList<int> EnumWindows()
You should add some Win32 API to filter windows. These APIs are the methods we plan to use.
// get class name of specific window
We can enumerate windows with specific class name by running the code,
public static IReadOnlyList<int> FindWindowByClassName(string className)
Also, you can change the method from
GetWindowText to enumerate windows by specific title.
var lpString = new StringBuilder(512);