c#

C#中FindWindow和FindWindowEx怎么使用

小亿
115
2023-10-12 02:44:42
栏目: 编程语言

在C#中,FindWindow和FindWindowEx函数用于查找窗口的句柄。以下是这两个函数的使用方法:

  1. FindWindow函数:
[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
IntPtr hWnd = FindWindow(null, "窗口标题");
  1. FindWindowEx函数:
[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函数来查找窗口的句柄了。

0
看了该问题的人还看了