| 278 | } |
| 279 | |
| 280 | long Apply(const std::vector<HWND> &windows, const std::vector<Rect> &rects, const Options &options) { |
| 281 | if (windows.empty() || windows.size() != rects.size()) { |
| 282 | return 0; |
| 283 | } |
| 284 | |
| 285 | for (size_t i = 0; i < windows.size(); ++i) { |
| 286 | if (!::IsWindow(windows[i])) { |
| 287 | return 0; |
| 288 | } |
| 289 | |
| 290 | const auto &rect = rects[i]; |
| 291 | Metrics initial_metrics = {}; |
| 292 | const bool has_initial_metrics = GetWindowMetrics(windows[i], initial_metrics); |
| 293 | if (!::SetWindowPos(windows[i], nullptr, rect.x, rect.y, rect.width, rect.height, |
| 294 | SWP_NOZORDER | SWP_NOACTIVATE)) { |
| 295 | return 0; |
| 296 | } |
| 297 | |
| 298 | // 某些窗口会吞掉尺寸修改,这里做一次结果校验,避免误报成功。 |
| 299 | ::Sleep(100); |
| 300 | if (options.anchor_mode == AnchorMode::Client) { |
| 301 | if (!MatchesTargetClientSize(windows[i], options)) { |
| 302 | return 0; |
| 303 | } |
| 304 | if (has_initial_metrics && !MatchesTargetClientRect(windows[i], rect, initial_metrics)) { |
| 305 | return 0; |
| 306 | } |
| 307 | } else if (!MatchesTargetSize(windows[i], rect)) { |
| 308 | return 0; |
| 309 | } |
| 310 | } |
| 311 | |
| 312 | return 1; |
| 313 | } |
| 314 | |
| 315 | long Layout(const std::vector<HWND> &windows, const Options &options) { |
| 316 | if (windows.empty()) { |
no test coverage detected