FindWindow 函数是 Win32 API 中的一个函数,用于查找与指定窗口类名或窗口标题匹配的顶级窗口。它不能直接查找子窗口。但是,你可以使用 FindWindowEx 函数来查找子窗口。
FindWindowEx 函数用于在 Z 顺序中查找窗口句柄。它需要以下参数:
- hwndParent:要开始搜索的父窗口句柄。如果为- IntPtr.Zero,则从桌面窗口开始搜索。
- hwndChildAfter:要开始搜索的第一个子窗口句柄。如果为- IntPtr.Zero,则从顶层窗口开始搜索。
- lpszClass:要查找的窗口类名。如果为- IntPtr.Zero,则使用窗口标题进行匹配。
- lpszWindow:要查找的窗口标题。
以下是一个使用 FindWindowEx 查找子窗口的示例:
using System;
using System.Runtime.InteropServices;
class Program
{
    [DllImport("user32.dll", SetLastError = true)]
    static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
    static void Main()
    {
        IntPtr parentHandle = IntPtr.Zero; // 替换为你要查找的父窗口句柄
        IntPtr childHandle = FindWindowEx(parentHandle, IntPtr.Zero, null, "Edit"); // 查找第一个类名为 "Edit" 的子窗口
        if (childHandle != IntPtr.Zero)
        {
            Console.WriteLine("找到了子窗口,句柄为: " + childHandle);
        }
        else
        {
            Console.WriteLine("未找到子窗口");
        }
    }
}
请注意,你需要根据实际情况替换 parentHandle 的值,以便查找正确的父窗口。

 便宜VPS测评
便宜VPS测评











