阅读量:2
FindWindow 函数是 Windows API 中的一个函数,用于根据窗口类名或窗口标题查找窗口。然而,FindWindow 函数并不能直接查找隐藏的窗口。
如果你想查找隐藏的窗口,可以使用 EnumWindows 函数枚举所有窗口,然后使用 IsWindowVisible 函数检查窗口是否可见。这是一个示例代码:
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
class Program
{
[DllImport("user32.dll")]
static extern bool EnumWindows(EnumWindowsDelegate lpEnumFunc, IntPtr lParam);
[DllImport("user32.dll")]
static extern bool IsWindowVisible(IntPtr hWnd);
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
delegate bool EnumWindowsDelegate(IntPtr hWnd, IntPtr lParam);
static void Main()
{
EnumWindows(EnumWindowsCallback, IntPtr.Zero);
}
static bool EnumWindowsCallback(IntPtr hWnd, IntPtr lParam)
{
if (IsWindowVisible(hWnd))
{
Console.WriteLine("Found visible window: " + new IntPtr(hWnd).ToString("X"));
}
return true;
}
}
这个示例代码会枚举所有可见的窗口并将其标题输出到控制台。请注意,这个方法只能查找可见的窗口,如果你想查找隐藏的窗口,你需要使用其他方法,例如监听窗口消息或使用钩子。
以上就是关于“C# FindWindow能查找隐藏窗口吗”的相关介绍,筋斗云是国内较早的云主机应用的服务商,拥有10余年行业经验,提供丰富的云服务器、租用服务器等相关产品服务。云服务器资源弹性伸缩,主机vCPU、内存性能强悍、超高I/O速度、故障秒级恢复;电子化备案,提交快速,专业团队7×24小时服务支持!
简单好用、高性价比云服务器租用链接:https://www.jindouyun.cn/product/cvm