| 203 | } |
| 204 | |
| 205 | BOOL CALLBACK Utils::EnumWindowsProc(HWND hwnd, LPARAM lParam) { |
| 206 | // 将 lParam 转换为 QStringList 的指针 |
| 207 | QStringList* windowTitles = reinterpret_cast<QStringList*>(lParam); |
| 208 | |
| 209 | // 获取窗口标题长度 |
| 210 | int length = GetWindowTextLength(hwnd); |
| 211 | if (length == 0) return TRUE; // 跳过没有标题的窗口 |
| 212 | |
| 213 | // 获取窗口标题 |
| 214 | wchar_t* buffer = new wchar_t[length + 1]; |
| 215 | GetWindowText(hwnd, buffer, length + 1); |
| 216 | |
| 217 | // 将标题存入 QStringList |
| 218 | windowTitles->append(QString::fromWCharArray(buffer)); |
| 219 | delete[] buffer; |
| 220 | |
| 221 | return TRUE; // 返回 TRUE 继续枚举 |
| 222 | } |
| 223 | |
| 224 | // 通过窗口标题获取句柄和 PID |
| 225 | bool Utils::getWindowHandleAndPID(const QString& windowTitle, HWND& hwnd, DWORD& pid) { |
nothing calls this directly
no outgoing calls
no test coverage detected