Esatto.Win32.CommonControls 3.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Esatto.Win32.CommonControls --version 3.0.0
NuGet\Install-Package Esatto.Win32.CommonControls -Version 3.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Esatto.Win32.CommonControls" Version="3.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Esatto.Win32.CommonControls --version 3.0.0
#r "nuget: Esatto.Win32.CommonControls, 3.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Esatto.Win32.CommonControls as a Cake Addin
#addin nuget:?package=Esatto.Win32.CommonControls&version=3.0.0

// Install Esatto.Win32.CommonControls as a Cake Tool
#tool nuget:?package=Esatto.Win32.CommonControls&version=3.0.0

Esatto Win32 Common Controls

Save Printer Settings

The entirety of the PrinterSettings – including vendor specific options – can be stored by persisting the HDEVMODE structure received via PrinterSettings.GetHdevmode(), then restored via PrinterSettings.SetHdevmode(IntPtr).

The class below will add two extension methods to save and restore PrinterSettings to and from a byte array.

Caveat programmer: some printer drivers do not have backwards or forwards compatibility, and may crash if using persisted data from another version or architecture of the driver.

Example Use:

PrinterSettings CurrentSettings;
const string myAppKeyName = @"Software\MyApplicationName";
const string printerSettingValueName = "PrinterSettings"

// save
using (var sk = Registry.CurrentUser.CreateSubKey(myAppKeyName))
{
    sk.SetValue(printerSettingValueName, this.CurrentSettings.GetDevModeData(), RegistryValueKind.Binary);
}

// restore
using (var sk = Registry.CurrentUser.CreateSubKey(myAppKeyName))
{
    var data = sk.GetValue(printerSettingValueName, RegistryValueKind.Binary) as byte[];

    this.CurrentSettings = new PrinterSettings();
    if (data != null)
    {
        this.CurrentSettings.SetDevModeData(data);
    }
}

Related: How can I save and restore PrinterSettings?

Non-closable window

Creates a WPF Window that has no "x" button.

<win32:NonClosableWindow x:Class="Example Window"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:win32="clr-namespace:Esatto.Win32.Wpf;assembly=Esatto.Win32.CommonControls"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    CanClose="{Binding Path=CanClose}"
    Title="Task Progress" ResizeMode="NoResize" SizeToContent="WidthAndHeight">
    <Grid>
    </Grid>
</win32:NonClosableWindow>

Watch for windows created from a specific process

this.WindowCreatedHook = new WinEventHook(this.FrameworkProcess, null, WinEvent.EVENT_OBJECT_SHOW, WinEvent.EVENT_OBJECT_HIDE, syncCtx: Sync);
this.WindowCreatedHook
    .Where(c => c.WinObject == WinObject.OBJID_WINDOW && c.WinChild == WinChild.CHILDID_SELF)
    .Subscribe(Hook_EventReceived);
    
private void Hook_EventReceived(WinEventEventArgs args)
{
    Console.WriteLine(args);
}

Create a "docked" window to some other process

var DockTarget = new Win32Window(0x12345678 /* Target HWND */)
this.LocationMonitor = new WindowLocationMonitor(DockTarget, DockTarget.GetParent());
this.LocationMonitor.WindowMoved += (_, e) => this.Location = Point.Add(e.WindowRect.Location.ToGdi(), DockTargetPositionOffset);
this.LocationMonitor.DragBegin += (_, _) => this.Hide();
this.LocationMonitor.DragEnd += (_, _) => this.Show();
this.LocationMonitor.Exception += (_, e) => Console.WriteLine("Exception on window location monitor: {0}", e.ExceptionObject);
this.Show();

Show Excel, Word, and other shell Preview handlers as a control

Add ShellPreviewControl to a Windows Form or WPF Window. Set DisplayedPath to an absolute path.

Create an "Open With" menu

var assocs = AssociatedHandler.ForPath(tempPath);
var cxm = new ContextMenu(
    assocs.Select(at => new MenuItem(at.DisplayName, (_1, _2) => at.Invoke())).ToArray());
cxm.Show(this, this.PointToClient(MousePosition));

Find and manipulate HWNDs

var foregroundCaption = Win32Window.GetForegrundWindow().CachedName;
var window = Win32Window.Find(process, w => w.CachedClass == "Example"" && window.GetIsShown());
var child = window.FindChild(ww => ww.CachedClass == FrameworkConstants.MdiClientClass);
child.Show();
Product Compatible and additional computed target framework versions.
.NET net7.0-windows7.0 is compatible.  net8.0-windows was computed. 
.NET Framework net48 is compatible.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
3.0.14 91 4/12/2024
3.0.10 186 12/14/2023
3.0.6 116 11/12/2023
3.0.5 94 11/9/2023
3.0.3 122 11/4/2023
3.0.2 117 10/31/2023
3.0.1 129 7/4/2023
3.0.0 168 4/29/2023
1.0.1 169 4/20/2023
1.0.0 169 4/20/2023