Esatto.Win32.CommonControls
3.0.10
See the version list below for details.
dotnet add package Esatto.Win32.CommonControls --version 3.0.10
NuGet\Install-Package Esatto.Win32.CommonControls -Version 3.0.10
<PackageReference Include="Esatto.Win32.CommonControls" Version="3.0.10" />
paket add Esatto.Win32.CommonControls --version 3.0.10
#r "nuget: Esatto.Win32.CommonControls, 3.0.10"
// Install Esatto.Win32.CommonControls as a Cake Addin #addin nuget:?package=Esatto.Win32.CommonControls&version=3.0.10 // Install Esatto.Win32.CommonControls as a Cake Tool #tool nuget:?package=Esatto.Win32.CommonControls&version=3.0.10
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 | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net7.0-windows7.0 is compatible. net8.0-windows was computed. |
.NET Framework | net462 is compatible. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
-
.NETFramework 4.6.2
- Esatto.Win32.Com (>= 3.0.9)
- System.Reactive.Linq (>= 5.0.0)
-
net7.0-windows7.0
- Esatto.Win32.Com (>= 3.0.9)
- System.Reactive.Linq (>= 5.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.