以下是一个使用C#编写的FindWindowEx示例代码,该代码用于查找具有特定类名和窗口名的顶层窗口:
using System;
using System.Runtime.InteropServices;
class Program
{
[DllImport("user32.dll")]
static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
static void Main()
{
// 查找具有特定类名和窗口名的顶层窗口
IntPtr hwnd = FindWindowEx(IntPtr.Zero, IntPtr.Zero, "ClassName", "WindowName");
if (hwnd != IntPtr.Zero)
{
Console.WriteLine("找到了窗口: " + hwnd);
}
else
{
Console.WriteLine("未找到窗口");
}
}
}
在这个示例中,我们使用了DllImport属性来导入user32.dll库中的FindWindowEx函数。然后,我们在Main方法中调用FindWindowEx函数,并传递IntPtr.Zero作为父窗口句柄和子窗口句柄,以便从最顶层窗口开始查找。我们还传递了要查找的窗口类的类名(ClassName)和窗口名(WindowName)。
如果找到了具有指定类名和窗口名的窗口,FindWindowEx函数将返回该窗口的句柄;否则,它将返回IntPtr.Zero。我们可以使用此句柄执行其他操作,例如获取窗口的尺寸或与其交互。

便宜VPS测评








