阅读量:4
以下是一个使用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。我们可以使用此句柄执行其他操作,例如获取窗口的尺寸或与其交互。
以上就是关于“c# findwindowex示例代码”的相关介绍,筋斗云是国内较早的云主机应用的服务商,拥有10余年行业经验,提供丰富的云服务器、租用服务器等相关产品服务。云服务器资源弹性伸缩,主机vCPU、内存性能强悍、超高I/O速度、故障秒级恢复;电子化备案,提交快速,专业团队7×24小时服务支持!
简单好用、高性价比云服务器租用链接:https://www.jindouyun.cn/product/cvm