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