Esatto.Win32.CommonControls 3.0.17

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.17                
NuGet\Install-Package Esatto.Win32.CommonControls -Version 3.0.17                
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.17" />                
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.17                
#r "nuget: Esatto.Win32.CommonControls, 3.0.17"                
#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.17

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

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();

Persist window location to registry

Create a window which when it opens will restore to the same location. Avoids restore if the window get's resized to be very small, or if monitor changes put it mostly outside of the desktop viewport. Restores maximized if the window is closed when maximized. Persists the restored size, and never restores minimized.

<Window x:Class="RememberWindowLocation.MainWindow"
        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"
        Title="MainWindow" Height="450" Width="800"
        win32:WindowPlacement.SavePath="Software\DemoApp\WindowPos">
</Window>
Product Compatible and additional computed target framework versions.
.NET net8.0-windows7.0 is compatible. 
.NET Framework net462 is compatible.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  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.19 69 11/3/2024
3.0.17 105 7/14/2024
3.0.14 126 4/12/2024
3.0.10 205 12/14/2023
3.0.6 136 11/12/2023
3.0.5 112 11/9/2023
3.0.3 140 11/4/2023
3.0.2 138 10/31/2023
3.0.1 147 7/4/2023
3.0.0 185 4/29/2023
1.0.1 189 4/20/2023
1.0.0 188 4/20/2023