#pragma once #include "config.hpp" #include #include #include struct ScreenCaptureSurface { HDC memoryDc = nullptr; HBITMAP bitmap = nullptr; HGDIOBJ oldBitmap = nullptr; std::uint8_t* pixels = nullptr; RECT rect{}; // local coordinates inside the virtual-desktop window int width = 0; int height = 0; int stride = 0; ScreenCaptureSurface() = default; ScreenCaptureSurface(const ScreenCaptureSurface&) = delete; ScreenCaptureSurface& operator=(const ScreenCaptureSurface&) = delete; ScreenCaptureSurface(ScreenCaptureSurface&& other) noexcept; ScreenCaptureSurface& operator=(ScreenCaptureSurface&& other) noexcept; ~ScreenCaptureSurface(); [[nodiscard]] bool valid() const noexcept { return memoryDc && bitmap && pixels && width > 0 && height > 0; } void reset() noexcept; }; struct ScreenCapture { int x = 0; int y = 0; int width = 0; int height = 0; std::vector surfaces; ScreenCapture() = default; ScreenCapture(const ScreenCapture&) = delete; ScreenCapture& operator=(const ScreenCapture&) = delete; ScreenCapture(ScreenCapture&&) noexcept = default; ScreenCapture& operator=(ScreenCapture&&) noexcept = default; ~ScreenCapture() = default; [[nodiscard]] bool valid() const noexcept { return width > 0 && height > 0 && !surfaces.empty(); } // Copies a local virtual-desktop rectangle into destination. Empty space // between physically arranged monitors is filled with black instead of // forcing NightShot to keep one enormous bounding-box DIB in RAM. [[nodiscard]] bool blitTo(HDC destination, int destinationX, int destinationY, const RECT& sourceLocal) const noexcept; [[nodiscard]] bool samplePixel(int localX, int localY, COLORREF& color) const noexcept; }; [[nodiscard]] ScreenCapture captureVirtualDesktop();