通过进程找窗口 - FindWindowByProcess
函数简介
根据进程名称、窗口类名和标题查找可见窗口。
接口名称
FindWindowByProcess
DLL调用
long FindWindowByProcess(long ola, string process_name, string class, string title);
参数说明
| 参数名 | 类型 | 说明 |
|---|---|---|
| ola | 长整数型 | OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。 |
| process_name | 字符串 | 进程名称(如 "notepad.exe"),精确匹配但不区分大小写。 |
| class | 字符串 | 窗口类名,支持模糊匹配。为空字符串则匹配所有类名。 |
| title | 字符串 | 窗口标题,支持模糊匹配。为空字符串则匹配所有标题。 |
示例
long hwnd = FindWindowByProcess(instance, "notepad.exe", "", "记事本");
if (hwnd != 0) {
printf("找到窗口,句柄: %ld\n", hwnd);
}
返回值
长整数型:找到的窗口句柄。未找到返回 0。
注意事项
- 进程名称必须包含扩展名(如
.exe),不区分大小写。 - 如果有多个匹配的窗口,返回第一个找到的窗口。
