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.
- 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
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
Duplicationclass: Handles DXGI setup, device management, and screen captureArgumentManager: Parses command-line arguments for customizationstb_image_write: Header-only library for PNG encoding- Modern C++20: Uses smart pointers, RAII, and standard library containers
- 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)
- DirectX 11 (
d3d11.lib,dxgi.lib) - Windows Shell API (
shell32.lib- automatically linked) - stb_image_write.h (included in project)
# Clone or extract the project
cd screenShot
# Create build directory
mkdir build
cd build
# Configure with CMake
cmake .. -G Ninja
# Build the project
ninja- Open the project folder in Visual Studio 2019+
- Visual Studio will automatically detect the CMake configuration
- Build the solution using
Ctrl+Shift+B
# Capture a 200x200 region from top-left corner
screenShot.exe
# The screenshot will be saved to your Documents folder as 'screenshot.png'# 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"| Parameter | Description | Default Value |
|---|---|---|
--width |
Capture width in pixels | 200 |
--height |
Capture height in pixels | 200 |
--output |
Output file path | screenshot.png |
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
- Initialize DirectX 11 Device: Creates hardware-accelerated D3D11 device
- Setup Desktop Duplication: Attaches to primary display output
- Acquire Frame: Captures current desktop frame into GPU texture
- Create Staging Texture: CPU-accessible copy for processing
- Map and Copy Data: Transfers pixel data to system memory
- Color Conversion: Converts BGRA to RGBA format
- PNG Encoding: Uses stb_image_write for file output
- 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
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
- 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)
"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
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
This project uses modern C++ practices and follows Windows development guidelines. When contributing:
- Maintain C++20 compatibility
- Use RAII for resource management
- Follow existing code style and naming conventions
- Test on multiple Windows versions when possible
- Update documentation for new features
This project is provided as-is for educational and development purposes. Please ensure compliance with your organization's policies regarding screen capture software.
- 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