通过进程找窗口 - FindWindowByProcessId
函数简介
根据进程ID、窗口类名和标题查找可见窗口。
接口名称
FindWindowByProcessId
DLL调用
long FindWindowByProcessId(long ola, long process_id, string class, string title);
参数说明
| 参数名 | 类型 | 说明 |
|---|---|---|
| ola | 长整数型 | OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。 |
| process_id | 长整数型 | 要查找的进程ID。 |
| class | 字符串 | 窗口类名,支持模糊匹配。为空字符串则匹配所有类名。 |
| title | 字符串 | 窗口标题,支持模糊匹配。为空字符串则匹配所有标题。 |
示例
long hwnd = FindWindowByProcessId(instance, 1234, "", "");
if (hwnd != 0) {
printf("找到窗口,句柄: %ld\n", hwnd);
}
返回值
长整数型:找到的窗口句柄。未找到返回 0。
注意事项
- 进程ID必须是当前运行的有效进程ID。
- 如果有多个匹配的窗口,返回第一个找到的窗口。
