Skip to content

xakep8/screenShotTool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ScreenShot - Windows Desktop Capture Tool

A high-performance Windows desktop screenshot application using DirectX Graphics Infrastructure (DXGI) Desktop Duplication API to capture screen regions and save them as PNG images.

Features

  • Hardware-accelerated screen capture using DXGI Desktop Duplication API
  • Full screen or region capture with customizable dimensions
  • PNG output format with proper color channel conversion (BGRA to RGBA)
  • Automatic file saving to Windows Documents folder
  • Command-line interface for automation and scripting
  • Multi-monitor support (captures primary display)
  • C++20 modern implementation with smart pointers and RAII

Technical Overview

This application leverages the Windows Desktop Duplication API, which provides:

  • Zero-copy desktop capture for maximum performance
  • Hardware acceleration through DirectX 11
  • Efficient memory management with staging textures
  • Real-time screen change detection

Architecture

  • Duplication class: Handles DXGI setup, device management, and screen capture
  • ArgumentManager: Parses command-line arguments for customization
  • stb_image_write: Header-only library for PNG encoding
  • Modern C++20: Uses smart pointers, RAII, and standard library containers

Requirements

System Requirements

  • Windows 10/11 (Windows 8+ supported)
  • DirectX 11 compatible graphics card
  • Visual Studio 2019+ or compatible C++20 compiler
  • CMake 3.8+ (tested with CMake 3.31.6)

Dependencies

  • DirectX 11 (d3d11.lib, dxgi.lib)
  • Windows Shell API (shell32.lib - automatically linked)
  • stb_image_write.h (included in project)

Building

Using CMake (Recommended)

# Clone or extract the project
cd screenShot

# Create build directory
mkdir build
cd build

# Configure with CMake
cmake .. -G Ninja

# Build the project
ninja

Using Visual Studio

  1. Open the project folder in Visual Studio 2019+
  2. Visual Studio will automatically detect the CMake configuration
  3. Build the solution using Ctrl+Shift+B

Usage

Basic Usage

# Capture a 200x200 region from top-left corner
screenShot.exe

# The screenshot will be saved to your Documents folder as 'screenshot.png'

Command Line Options

# Specify custom dimensions
screenShot.exe --width 640 --height 480

# Custom output path
screenShot.exe --output "C:\My Screenshots\capture.png"

# Combined usage
screenShot.exe --width 1024 --height 768 --output "desktop_capture.png"

Available Parameters

Parameter Description Default Value
--width Capture width in pixels 200
--height Capture height in pixels 200
--output Output file path screenshot.png

Code Structure

screenShot/
??? CMakeLists.txt              # Main CMake configuration
??? screenShot/
?   ??? CMakeLists.txt          # Project-specific CMake
?   ??? screenShot.cpp          # Main application entry point
?   ??? screenShot.h            # Main header file
?   ??? Duplication.h           # DXGI Desktop Duplication wrapper
?   ??? Duplication.cpp         # Core capture implementation
?   ??? ArgumentManager.h       # Command-line argument parsing
?   ??? ArgumentManger.cpp      # Argument parsing implementation
?   ??? stb_image_write.h       # PNG encoding library
??? README.md                   # This file

Technical Implementation Details

Screen Capture Process

  1. Initialize DirectX 11 Device: Creates hardware-accelerated D3D11 device
  2. Setup Desktop Duplication: Attaches to primary display output
  3. Acquire Frame: Captures current desktop frame into GPU texture
  4. Create Staging Texture: CPU-accessible copy for processing
  5. Map and Copy Data: Transfers pixel data to system memory
  6. Color Conversion: Converts BGRA to RGBA format
  7. PNG Encoding: Uses stb_image_write for file output

Performance Characteristics

  • Capture Latency: ~1-5ms depending on screen content changes
  • Memory Usage: Scales with capture region size (4 bytes per pixel)
  • CPU Usage: Minimal - most work done on GPU
  • File I/O: Direct PNG encoding without intermediate formats

Error Handling

The application includes comprehensive error handling for:

  • Graphics device initialization failures
  • Desktop duplication API errors
  • File system access issues
  • Invalid command-line arguments
  • Memory allocation failures

Limitations

  • Windows Only: Uses Windows-specific DXGI APIs
  • Primary Display: Currently captures only the primary monitor
  • Administrator Rights: May require elevated privileges in some environments
  • Remote Desktop: Limited functionality in RDP sessions
  • DRM Content: Cannot capture protected content (by design)

Troubleshooting

Common Issues

"Error starting capturer"

  • Ensure graphics drivers are up to date
  • Try running as Administrator
  • Check if running in a virtual machine or remote desktop

"Buffer appears to be empty"

  • Screen may not have changed recently (try moving the mouse)
  • Verify the capture region is within screen bounds
  • Check for DRM-protected content in the capture area

Build Errors

  • Ensure C++20 support is enabled
  • Verify CMake version is 3.8 or higher
  • Check that Windows SDK is properly installed

Debug Output

The application provides detailed logging:

[CAPTURER] Documents folder path: C:\Users\Username\Documents\
[CAPTURER] Capturing screen with resolution: 1920x1080
[CAPTURER] Waiting for frame...
[CAPTURER] screenshot saved to screenshot.png

Contributing

This project uses modern C++ practices and follows Windows development guidelines. When contributing:

  1. Maintain C++20 compatibility
  2. Use RAII for resource management
  3. Follow existing code style and naming conventions
  4. Test on multiple Windows versions when possible
  5. Update documentation for new features

License

This project is provided as-is for educational and development purposes. Please ensure compliance with your organization's policies regarding screen capture software.

Acknowledgments

  • Microsoft: For the DXGI Desktop Duplication API documentation
  • Sean Barrett: For the excellent stb_image_write library
  • CMake Community: For the build system and toolchain support

About

This is a cross platform cli tool to capture screenshots of the entire screen or a specific region. Uses DXGI on windows and CoreGraphics on MacOS to capture the screen image.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors