| 484 | |
| 485 | |
| 486 | bool CColorCopDlg::LoadPersistentVariables() { |
| 487 | TRACE(_T("Portable mode: %d\n"), m_PortableMode); |
| 488 | |
| 489 | // Build full bitmap path safely |
| 490 | auto* pApp = static_cast<CColorCopApp*>(AfxGetApp()); |
| 491 | CString strBMPFile = pApp->GetSettingsFolder(); |
| 492 | strBMPFile += BMP_FILE; |
| 493 | |
| 494 | TRACE(_T("BMP path: %s\n"), strBMPFile.GetString()); |
| 495 | |
| 496 | // Load bitmap from file |
| 497 | hBitmap = reinterpret_cast<HBITMAP>( |
| 498 | LoadImage(AfxGetApp()->m_hInstance, |
| 499 | strBMPFile, |
| 500 | IMAGE_BITMAP, |
| 501 | 0, 0, |
| 502 | LR_LOADFROMFILE)); |
| 503 | |
| 504 | if (hBitmap) { |
| 505 | hZoomBitmap = hBitmap; |
| 506 | } else { |
| 507 | TRACE(_T("Warning: Could not load bitmap: %s\n"), strBMPFile.GetString()); |
| 508 | } |
| 509 | |
| 510 | // |
| 511 | // Off‑screen recovery: If the saved window position is off-screen, reset to defaults. |
| 512 | // Use the full virtual desktop (multi‑monitor safe) |
| 513 | // |
| 514 | RECT virtualBounds; |
| 515 | virtualBounds.left = GetSystemMetrics(SM_XVIRTUALSCREEN); |
| 516 | virtualBounds.top = GetSystemMetrics(SM_YVIRTUALSCREEN); |
| 517 | virtualBounds.right = virtualBounds.left + GetSystemMetrics(SM_CXVIRTUALSCREEN); |
| 518 | virtualBounds.bottom = virtualBounds.top + GetSystemMetrics(SM_CYVIRTUALSCREEN); |
| 519 | |
| 520 | constexpr int kVisibilityMargin = 100; // px |
| 521 | |
| 522 | bool offscreen = |
| 523 | (WinLocX > virtualBounds.right) || |
| 524 | (WinLocY > virtualBounds.bottom) || |
| 525 | (WinLocX + kVisibilityMargin < virtualBounds.left) || |
| 526 | (WinLocY + kVisibilityMargin < virtualBounds.top); |
| 527 | |
| 528 | if (offscreen) { |
| 529 | WinLocX = kDefaultWinLocX; |
| 530 | WinLocY = kDefaultWinLocY; |
| 531 | } |
| 532 | |
| 533 | // Restore window position (no size change) |
| 534 | ::SetWindowPos(GetSafeHwnd(), |
| 535 | (m_Appflags & AlwaysOnTop) ? HWND_TOPMOST : HWND_NOTOPMOST, |
| 536 | WinLocX, WinLocY, |
| 537 | 0, 0, |
| 538 | SWP_NOSIZE); |
| 539 | // Ensure zoom level is valid after loading settings |
| 540 | m_MagLevel = std::clamp<int>(m_MagLevel, kMinZoom, kMaxZoom); |
| 541 | |
| 542 | return true; |
| 543 | } |
nothing calls this directly
no test coverage detected