溫馨提示×

C#中FindWindow和FindWindowEx怎么使用

c#
小億
465
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, "窗口標題");
  • lpClassName參數指定窗口的類名,如果為null,則忽略該參數。

  • lpWindowName參數指定窗口的標題,如果為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, "子窗口標題");
  • hWndParent參數指定父窗口的句柄,如果為IntPtr.Zero,則從所有頂層窗口中查找。

  • hWndChildAfter參數指定子窗口的句柄,如果為IntPtr.Zero,則從第一個子窗口開始查找。

  • lpszClass參數指定子窗口的類名,如果為null,則忽略該參數。

  • lpszWindow參數指定子窗口的標題,如果為null,則忽略該參數。

注意:在使用上述函數之前,需要將以下命名空間引入項目中:

using System.Runtime.InteropServices;

這樣就可以在C#中使用FindWindow和FindWindowEx函數來查找窗口的句柄了。

0
亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女