FindWindow 函数:在 C# 中查找 Windows 窗口
FindWindow 是 Windows API 中定义的函数,用于查找具有指定类名和窗口名的顶层窗口。
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
在 C# 中,我们可以使用 DllImport 特性来导入 user32.dll 动态链接库中的 FindWindow 函数。
FindWindow 函数接受两个参数:
- 'lpClassName':要查找的窗口的类名。可以传递 'null' 或空字符串来匹配任何类名的窗口。
- 'lpWindowName':要查找的窗口的标题(窗口名)。可以传递 'null' 或空字符串来匹配任何窗口标题。
函数返回一个 IntPtr 类型的句柄(handle),表示找到的窗口的标识符。如果函数未找到匹配的窗口,返回值将是 IntPtr.Zero。
通过调用 FindWindow 函数,并传递目标窗口的类名和窗口名,我们可以获取该窗口的句柄,以便在后续的操作中引用该窗口。
原文地址: https://www.cveoy.top/t/topic/PRF 著作权归作者所有。请勿转载和采集!