C#中FindWindow和FindWindowEx如何使用
在C#中,FindWindow和FindWindowEx函数用于查找窗口的句柄。以下是这两个函数的使用方法:
[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
IntPtr hWnd = FindWindow(null, "窗口标题");
[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr FindWindowEx(IntPtr hWndParent, IntPtr hWndChildAfter, string lpszClass, string lpszWindow);
IntPtr hWndChild = FindWindowEx(hWndParent, IntPtr.Zero, null, "子窗口标题");
注意:在使用上述函数之前,需要将以下命名空间引入项目中:
using System.Runtime.InteropServices;
这样就能够在C#中使用FindWindow和FindWindowEx函数来查找窗口的句柄了。
TOP