枚举窗口 - EnumWindow
函数简介
根据指定条件,枚举系统中符合条件的窗口。
接口名称
EnumWindow
DLL调用
long EnumWindow(long ola, long parent, string title, string class_name, int filter);
参数说明
| 参数名 | 类型 | 说明 |
|---|---|---|
| ola | 长整数型 | OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。 |
| parent | 长整数型 | 父窗口句柄,为 0 时获取桌面的子窗口。 |
| title | 字符串 | 窗口标题,支持模糊匹配。为空字符串则不匹配标题。 |
| class_name | 字符串 | 窗口类名,支持模糊匹配。为空字符串则不匹配类名。 |
| filter | 整数型 | 过滤条件,可组合使用(值相加)。 |
filter 过滤条件
| 值 | 说明 |
|---|---|
| 1 | 匹配窗口标题(参数title有效)。 |
| 2 | 匹配窗口类名(参数class_name有效)。 |
| 4 | 只匹配第一个进程的窗口。 |
| 8 | 匹配顶级窗口(所有者窗口为0)。 |
| 16 | 匹配可见窗口。 |
示例
// 查找所有可见的顶级窗口,标题包含"记事本"
long ret = EnumWindow(instance, 0, "记事本", "", 1 + 8 + 16);
if (ret != 0) {
// 返回格式为 "hwnd1,hwnd2,hwnd3"
FreeStringPtr(ret);
}
返回值
字符串指针地址,包含所有匹配的窗口句柄,格式为 "hwnd1,hwnd2,hwnd3"。未找到返回空字符串。
注意事项
- DLL调用返回字符串指针地址,需要调用 FreeStringPtr 接口释放内存。
- 过滤条件可以组合使用,例如
1+8+16表示匹配标题、顶级窗口和可见窗口。
