← Back to projects

DisplayProfileManager

Software August 2024 Read in Chinese
C# WPF Windows API P/Invoke

Problem

Switching display configurations in a multi-monitor setup is repetitive and tedious. Connecting to a projector requires adjusting resolution and arrangement. Returning to the workstation means switching back to the original three-monitor layout. The built-in Windows display settings require manual drag-and-drop every time, which is inefficient for frequent switching.

Solution

Developed DisplayProfileManager, a WPF desktop application that lets users save multiple display configurations as profiles and switch between them with a single click or system tray shortcut.

Core features:

  • Detect all connected monitors and their capabilities (resolution, refresh rate, color depth)
  • Save complete display configuration as a profile (positions, primary monitor, scaling)
  • One-click profile application
  • System tray resident with hotkey support
  • Monitor hotplug detection with automatic profile suggestion

Technical Challenges

Windows Display API

Windows provides no high-level “save and restore display configuration” API. The actual implementation requires P/Invoke calls to low-level Win32 functions:

  • EnumDisplayDevices: Enumerate display devices
  • EnumDisplaySettingsEx: Retrieve display settings
  • ChangeDisplaySettingsEx: Apply display settings

The flag combinations for ChangeDisplaySettingsEx critically affect behavior. Achieving flicker-free multi-monitor switching requires using CDS_UPDATEREGISTRY | CDS_NORESET to write all settings first, then a final call with CDS_SET_PRIMARY to apply.

Screen Coordinate System

Windows screen coordinates use the primary monitor’s top-left corner as the origin. When the primary monitor changes, all absolute coordinates are recalculated. Profiles store relative position relationships, requiring absolute coordinate recalculation based on the current primary monitor during application.

Results

  • Switching time reduced from 30-60 seconds of manual operation to under 1 second
  • Used by approximately 15 colleagues internally, covering conference room projectors, test workstations, and personal desks