JFLib

plat/win_screen.rs (Windows)#

Source: lib/plat/win_screen.rs

win_screen -- (screen.rs) the monitors, pictures of the screen and the colour pick on Windows

  monitors() -> Vec<Monitor>   EnumDisplayMonitors; per monitor GetMonitorInfoW (MONITORINFOEXW:
                               rectangle, work area, MONITORINFOF_PRIMARY, the device name),
                               GetDpiForMonitor (shcore, effective dpi; else the system's),
                               EnumDisplaySettingsW (ENUM_CURRENT_SETTINGS: dmDisplayFrequency)
  capture_start(rect)          BitBlt (SRCCOPY | CAPTUREBLT) from the screen DC into a top-down
                               32-bit DIB section, answered at once (ScreenEvent::Shot)
  pick_start(test)             a frozen picture of the virtual desktop in a topmost window over
                               all monitors, a magnifier (9 x 9 pixels) beside the pointer with
                               the colour and its hex value; a left click, Enter or Space takes
                               the pixel under the pointer, the arrows move the pointer by one
                               pixel (Shift: ten), Esc / a right click cancels.  test = Some(x,
                               y): that pixel at once (1 x 1 BitBlt), no window
  (test aid) screen_test_metrics() -> (SM_CMONITORS, virtual desktop rectangle), the
                               independent figures of GetSystemMetrics

The process is made per-monitor DPI aware first (win_api.rs), so every figure is in physical
pixels of the virtual desktop.  WM_DISPLAYCHANGE and a changed work area (SPI_SETWORKAREA)
reach the app as E_SETTINGS with SET_MONITORS (win_api.rs).  The overlay belongs to the UI
thread: its messages are dispatched by wait().
  • fn screen_test_metrics() -> (i32, [i32; 4]) (test aid) GetSystemMetrics: the number of monitors and the virtual desktop x, y, w, h

  • fn pick_test_window() -> isize (test aid) the pick overlay's window, 0 = none (tests close it with Esc through it)

  • fn pick_test_click(x: i32, y: i32) -> bool (test aid) pointer at the desktop point x, y of the open pick and a click there, as the window would see it -> false without a pick

  • fn pick_test_move(x: i32, y: i32) -> bool (test aid) the pointer at the desktop point x, y of the open pick (the magnifier follows on the next WM_PAINT); the real pointer's moves are ignored from then on -> false without a pick

  • fn pick_test_cancel() -> bool (test aid) Esc in the open pick -> false without a pick

  • fn screen_test_topmost(w: i32) -> bool (test aid) window w above every other window (HWND_TOPMOST), shown without activation, so a picture of the screen shows it -> false without the window

Source: docs/API.md in the JFLib repository.