SkillAgentSearch skills...

Dapplo.Windows

A library with a different approach to calling Win32 APIs, e,g providing reactive access to the clipboard or global hotkeys.

Install / Use

/learn @dapplo/Dapplo.Windows
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

Dapplo.Windows

A comprehensive .NET library providing Windows-specific functionality for .NET Framework and .NET Core applications.

Overview

Dapplo.Windows is a collection of packages that provide P/Invoke wrappers and higher-level abstractions for Windows API functionality. Originally developed for Greenshot, this library makes it easy to interact with Windows features from managed code.

Build Status & NuGet Packages

Build and Deploy Coverage Status

Core Packages

| Package | NuGet | Description | |---------|-------|-------------| | Dapplo.Windows | NuGet | Window management and event hooking | | Dapplo.Windows.Clipboard | NuGet | Clipboard monitoring and manipulation | | Dapplo.Windows.Dpi | NuGet | DPI awareness and scaling | | Dapplo.Windows.Input | NuGet | Keyboard and mouse input |

Low-Level API Packages

| Package | NuGet | Description | |---------|-------|-------------| | Dapplo.Windows.User32 | NuGet | User32.dll wrappers | | Dapplo.Windows.Gdi32 | NuGet | GDI32.dll wrappers | | Dapplo.Windows.Kernel32 | NuGet | Kernel32.dll wrappers |

Specialized Packages

| Package | NuGet | Description | |---------|-------|-------------| | Dapplo.Windows.Citrix | NuGet | Citrix environment detection | | Dapplo.Windows.DesktopWindowsManager | NuGet | DWM (Aero) functionality | | Dapplo.Windows.EmbeddedBrowser | NuGet | Enhanced WebBrowser control | | Dapplo.Windows.Messages | NuGet | Windows message definitions | | Dapplo.Windows.Com | NuGet | COM interop helpers | | Dapplo.Windows.Common | NuGet | Shared types and utilities |

Features

Window Management

  • Query window properties (title, bounds, class name, process, etc.)
  • Enumerate windows with filtering
  • Monitor window events (creation, destruction, title changes, etc.)
  • Manipulate windows (show, hide, minimize, maximize, move, resize)

Input Handling

  • Low-level keyboard hooks using Reactive Extensions
  • Low-level mouse hooks using Reactive Extensions
  • Generate keyboard input (type text, key combinations)
  • Generate mouse input (move, click, scroll)
  • Key combination and sequence handlers

Clipboard

  • Monitor clipboard changes with Reactive Extensions
  • Access clipboard content in various formats (text, files, images, streams)
  • Set clipboard content
  • Delayed rendering support
  • Control Windows Cloud Clipboard and Clipboard History behavior

DPI Awareness

  • DPI-aware forms for Windows Forms
  • DPI handlers for custom scaling logic
  • DPI calculations and conversions
  • Bitmap scaling with quality preservation
  • Support for both Windows Forms and WPF

Session Management

  • Monitor Windows session changes (lock/unlock, logon/logoff)
  • Handle session events with simple event-based API
  • Pause/resume session monitoring
  • Support for all WTS session change events

Native API Access

  • Comprehensive User32 API wrappers
  • GDI32 graphics API wrappers
  • Kernel32 system API wrappers
  • Proper SafeHandle usage for resource management
  • Well-defined structs and enums

Additional Features

  • Citrix session detection and querying
  • Desktop Window Manager (DWM) integration
  • Enhanced WebBrowser control with configurable IE version
  • Software installation enumeration
  • Icon extraction
  • And much more...

Quick Start

Installation

Install-Package Dapplo.Windows
Install-Package Dapplo.Windows.Clipboard
Install-Package Dapplo.Windows.Dpi
Install-Package Dapplo.Windows.Input

Examples

Monitor Window Title Changes

using Dapplo.Windows.Desktop;

var subscription = WinEventHook.Create(WinEvents.EVENT_OBJECT_NAMECHANGE)
    .Subscribe(winEvent =>
    {
        var window = InteropWindow.FromHandle(winEvent.Handle);
        Console.WriteLine($"Window title changed: {window.GetCaption()}");
    });

Monitor Clipboard

using Dapplo.Windows.Clipboard;
using System.Reactive.Linq;

var subscription = ClipboardNative.OnUpdate
    .Where(info => info.Formats.Contains("Text"))
    .Subscribe(info =>
    {
        using var clipboard = ClipboardNative.Access();
        var text = clipboard.GetAsString();
        Console.WriteLine($"Clipboard: {text}");
    });

Control Cloud Clipboard and History

using Dapplo.Windows.Clipboard;

// Prevent sensitive data from being saved to clipboard history or cloud
using (var clipboard = ClipboardNative.Access())
{
    clipboard.SetAsUnicodeString("MyPassword123!");
    clipboard.SetCloudClipboardOptions(
        canIncludeInHistory: false,
        canUploadToCloud: false
    );
}

Create DPI-Aware Form

using Dapplo.Windows.Dpi.Forms;

public class MyForm : DpiAwareForm
{
    public MyForm()
    {
        InitializeComponent();
        // Form automatically scales with DPI changes
    }
}

Hook Keyboard Input

using Dapplo.Windows.Input.Keyboard;
using System.Reactive.Linq;

var keyboardHook = KeyboardHook.Create();
var subscription = keyboardHook.KeyboardEvents
    .Where(e => e.Key == VirtualKeyCode.A && e.IsDown)
    .Subscribe(e => Console.WriteLine("'A' pressed"));

Monitor Session Changes (Lock/Unlock, Logon/Logoff)

using Dapplo.Windows.Messages;

var sessionListener = new WindowsSessionListener();

// Handle lock/unlock events
sessionListener.SessionLockChange += (sender, args) =>
{
    if (args.EventType == WtsSessionChangeEvents.WTS_SESSION_LOCK)
    {
        Console.WriteLine("Session locked");
        // Perform actions when session is locked
    }
    else if (args.EventType == WtsSessionChangeEvents.WTS_SESSION_UNLOCK)
    {
        Console.WriteLine("Session unlocked");
        // Perform actions when session is unlocked
    }
};

// Handle logon/logoff events
sessionListener.SessionLogonChange += (sender, args) =>
{
    if (args.EventType == WtsSessionChangeEvents.WTS_SESSION_LOGON)
    {
        Console.WriteLine("User logged on");
    }
    else if (args.EventType == WtsSessionChangeEvents.WTS_SESSION_LOGOFF)
    {
        Console.WriteLine("User logged off");
    }
};

sessionListener.Start();

// Pause/resume listening
sessionListener.Pause();
sessionListener.Resume();

// Clean up when done
sessionListener.Dispose();

Documentation

Examples

The repository includes example projects:

  • Dapplo.Windows.Example.ConsoleDemo - Console application examples
  • Dapplo.Windows.Example.FormsExample - Windows Forms examples
  • Dapplo.Windows.Example.WpfExample - WPF application examples

Requirements

  • .NET Framework 4.6.2 or higher
  • .NET Core 3.1 or higher / .NET 5+ (for most packages)
  • Windows operating system

Contributing

Contributions are welcome! Please feel free to submit issues and pull requests.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

Originally developed for Greenshot, this library has been extracted into a standalone project for easier maintenance and reuse.

View on GitHub
GitHub Stars142
CategoryDevelopment
Updated2d ago
Forks21

Languages

C#

Security Score

100/100

Audited on Apr 1, 2026

No findings