MCPcopy Create free account
hub / github.com/Hashiao/wuwaBackendTool / getWindowHandleAndPID

Method getWindowHandleAndPID

utils.cpp:225–241  ·  view source on GitHub ↗

通过窗口标题获取句柄和 PID

Source from the content-addressed store, hash-verified

223
224// 通过窗口标题获取句柄和 PID
225bool 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
244QImage Utils::captureWindowToQImage(HWND hwnd, const DWORD mode) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected