通过窗口标题获取句柄和 PID
| 223 | |
| 224 | // 通过窗口标题获取句柄和 PID |
| 225 | bool Utils::getWindowHandleAndPID(const QString& windowTitle, HWND& hwnd, DWORD& pid) { |
| 226 | // 使用 FindWindow 查找窗口句柄 |
| 227 | hwnd = FindWindow(nullptr, (LPCWSTR)windowTitle.utf16()); |
| 228 | if (!hwnd) { |
| 229 | qWarning() << "Window not found for title:" << windowTitle; |
| 230 | return false; |
| 231 | } |
| 232 | |
| 233 | // 获取进程 ID |
| 234 | DWORD threadId = GetWindowThreadProcessId(hwnd, &pid); |
| 235 | if (threadId == 0) { |
| 236 | qWarning() << "Failed to get process ID for window title:" << windowTitle; |
| 237 | return false; |
| 238 | } |
| 239 | |
| 240 | return true; |
| 241 | } |
| 242 | |
| 243 | // 捕获窗口内容并转换为 QImage |
| 244 | QImage Utils::captureWindowToQImage(HWND hwnd, const DWORD mode) { |
nothing calls this directly
no outgoing calls
no test coverage detected