add function codes
This commit is contained in:
1 parent
cae862d6b0
commit
c1d6e901b2
31 files changed
+2428
-169
No files matched your search
@@ -48,12 +48,9 @@
|
||||
</Style>
|
||||
|
||||
<Style TargetType="Window">
|
||||
<Setter Property="UseLayoutRounding" Value="True"/>
|
||||
</Style>
|
||||
|
||||
<Style x:Key="WindowDefault" TargetType="Window">
|
||||
<Setter Property="Background" Value="{DynamicResource BackgroundBrush}"/>
|
||||
<Setter Property="Background" Value="{DynamicResource RegionBrush}"/>
|
||||
<Setter Property="Foreground" Value="{DynamicResource PrimaryTextBrush}"/>
|
||||
<Setter Property="UseLayoutRounding" Value="True"/>
|
||||
</Style>
|
||||
|
||||
<Style x:Key="WindowWin10" TargetType="controls:Window">
|
||||
|
||||
@@ -49,12 +49,9 @@
|
||||
</Style>
|
||||
|
||||
<Style TargetType="Window">
|
||||
<Setter Property="UseLayoutRounding" Value="True"/>
|
||||
</Style>
|
||||
|
||||
<Style x:Key="WindowDefault" BasedOn="{x:Null}" TargetType="Window">
|
||||
<Setter Property="Background" Value="{DynamicResource BackgroundBrush}"/>
|
||||
<Setter Property="Background" Value="{DynamicResource RegionBrush}"/>
|
||||
<Setter Property="Foreground" Value="{DynamicResource PrimaryTextBrush}"/>
|
||||
<Setter Property="UseLayoutRounding" Value="True"/>
|
||||
</Style>
|
||||
|
||||
<Style x:Key="WindowWin10" BasedOn="{x:Null}" TargetType="controls:Window">
|
||||
@@ -182,6 +179,10 @@
|
||||
<Setter Property="Background" Value="Transparent"/>
|
||||
</Style>
|
||||
|
||||
<Style x:Key="WindowGlow">
|
||||
|
||||
</Style>
|
||||
|
||||
<Style TargetType="controls:ImageBrowser">
|
||||
<Setter Property="Background" Value="Transparent"/>
|
||||
<Setter Property="MinWidth" Value="400"/>
|
||||
|
||||
@@ -48,12 +48,9 @@
|
||||
</Style>
|
||||
|
||||
<Style TargetType="Window">
|
||||
<Setter Property="UseLayoutRounding" Value="True"/>
|
||||
</Style>
|
||||
|
||||
<Style x:Key="WindowDefault" TargetType="Window">
|
||||
<Setter Property="Background" Value="{DynamicResource BackgroundBrush}"/>
|
||||
<Setter Property="Background" Value="{DynamicResource RegionBrush}"/>
|
||||
<Setter Property="Foreground" Value="{DynamicResource PrimaryTextBrush}"/>
|
||||
<Setter Property="UseLayoutRounding" Value="True"/>
|
||||
</Style>
|
||||
|
||||
<Style x:Key="WindowWin10" TargetType="controls:Window">
|
||||
|
||||
@@ -56,6 +56,7 @@ namespace HandyControlDemo
|
||||
UpdateSkin(GlobalData.Config.Skin);
|
||||
}
|
||||
|
||||
ConfigHelper.Instance.SetWindowDefaultStyle();
|
||||
ConfigHelper.Instance.SetSystemVersionInfo(CommonHelper.GetSystemVersionInfo());
|
||||
|
||||
ServicePointManager.SecurityProtocol = (SecurityProtocolType)(SslProtocols)0x00000C00;
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
xmlns:userControl="clr-namespace:HandyControlDemo.UserControl"
|
||||
xmlns:data="clr-namespace:HandyControlDemo.Data"
|
||||
mc:Ignorable="d"
|
||||
Style="{StaticResource WindowBlur}"
|
||||
Title="HandyControlDemo"
|
||||
ShowTitle="False"
|
||||
ResizeMode="CanResizeWithGrip"
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
ShowTitle="True"
|
||||
BorderThickness="1"
|
||||
BorderBrush="#262e2f"
|
||||
Style="{StaticResource WindowWin10}"
|
||||
ResizeMode="NoResize"
|
||||
ShowInTaskbar="False"
|
||||
WindowStartupLocation="CenterOwner"
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
mc:Ignorable="d"
|
||||
WindowStartupLocation="CenterScreen"
|
||||
Title="{x:Static langs:Lang.Title}"
|
||||
Style="{StaticResource WindowBlur}"
|
||||
Height="450"
|
||||
Width="800"
|
||||
Icon="/HandyControlDemo;component/Resources/Img/icon.ico">
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
mc:Ignorable="d"
|
||||
Background="{DynamicResource MainContentBackgroundBrush}"
|
||||
WindowStartupLocation="CenterScreen"
|
||||
Style="{StaticResource WindowWin10}"
|
||||
Title="{x:Static langs:Lang.Title}"
|
||||
Height="450"
|
||||
Width="800"
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
NonClientAreaHeight="69"
|
||||
Background="{DynamicResource MainContentBackgroundBrush}"
|
||||
WindowStartupLocation="CenterScreen"
|
||||
Style="{StaticResource WindowWin10}"
|
||||
ShowTitle="False"
|
||||
Title="{x:Static langs:Lang.Title}"
|
||||
Height="450"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<hc:GlowWindow x:Class="HandyControlDemo.Window.GlowWindow"
|
||||
<Window x:Class="HandyControlDemo.Window.GlowWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
@@ -14,4 +14,4 @@
|
||||
<Grid>
|
||||
|
||||
</Grid>
|
||||
</hc:GlowWindow>
|
||||
</Window>
|
||||
@@ -8,7 +8,6 @@
|
||||
mc:Ignorable="d"
|
||||
WindowStartupLocation="CenterScreen"
|
||||
ShowTitle="True"
|
||||
Style="{StaticResource WindowBlur}"
|
||||
Icon="/HandyControlDemo;component/Resources/Img/icon.ico"
|
||||
ShowNonClientArea="False"
|
||||
Title="NoClientDragableWindow"
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
using HandyControl.Data;
|
||||
using HandyControl.Tools;
|
||||
@@ -7,6 +8,11 @@ namespace HandyControl.Controls
|
||||
{
|
||||
public class BlurWindow : Window
|
||||
{
|
||||
static BlurWindow()
|
||||
{
|
||||
StyleProperty.OverrideMetadata(typeof(BlurWindow), new FrameworkPropertyMetadata(Application.Current.FindResource(ResourceToken.WindowBlur)));
|
||||
}
|
||||
|
||||
public override void OnApplyTemplate()
|
||||
{
|
||||
base.OnApplyTemplate();
|
||||
|
||||
@@ -1,7 +1,666 @@
|
||||
namespace HandyControl.Controls
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Interop;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Threading;
|
||||
using HandyControl.Data;
|
||||
using HandyControl.Expression.Drawing;
|
||||
using HandyControl.Tools;
|
||||
using HandyControl.Tools.Extension;
|
||||
using HandyControl.Tools.Interop;
|
||||
|
||||
namespace HandyControl.Controls
|
||||
{
|
||||
public class GlowWindow : System.Windows.Window
|
||||
{
|
||||
|
||||
internal int DeferGlowChangesCount;
|
||||
|
||||
private IntPtr _ownerForActivate;
|
||||
|
||||
private readonly GlowEdge[] _glowEdges = new GlowEdge[4];
|
||||
|
||||
private DispatcherTimer _makeGlowVisibleTimer;
|
||||
|
||||
private bool _isGlowVisible;
|
||||
|
||||
private bool _useLogicalSizeForRestore;
|
||||
|
||||
private bool _isNonClientStripVisible;
|
||||
|
||||
private bool _updatingZOrder;
|
||||
|
||||
private int _lastWindowPlacement;
|
||||
|
||||
private Rect _logicalSizeForRestore = Rect.Empty;
|
||||
|
||||
public static readonly DependencyProperty ActiveGlowColorProperty = DependencyProperty.Register(
|
||||
"ActiveGlowColor", typeof(Color), typeof(GlowWindow), new PropertyMetadata(default(Color), OnGlowColorChanged));
|
||||
|
||||
public Color ActiveGlowColor
|
||||
{
|
||||
get => (Color)GetValue(ActiveGlowColorProperty);
|
||||
set => SetValue(ActiveGlowColorProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty InactiveGlowColorProperty = DependencyProperty.Register(
|
||||
"InactiveGlowColor", typeof(Color), typeof(GlowWindow), new PropertyMetadata(default(Color), OnGlowColorChanged));
|
||||
|
||||
public Color InactiveGlowColor
|
||||
{
|
||||
get => (Color)GetValue(InactiveGlowColorProperty);
|
||||
set => SetValue(InactiveGlowColorProperty, value);
|
||||
}
|
||||
|
||||
static GlowWindow()
|
||||
{
|
||||
StyleProperty.OverrideMetadata(typeof(GlowWindow), new FrameworkPropertyMetadata(Application.Current.FindResource(ResourceToken.WindowGlow)));
|
||||
ResizeModeProperty.OverrideMetadata(typeof(GlowWindow), new FrameworkPropertyMetadata(OnResizeModeChanged));
|
||||
}
|
||||
|
||||
public void ChangeOwnerForActivate(IntPtr newOwner)
|
||||
{
|
||||
_ownerForActivate = newOwner;
|
||||
}
|
||||
|
||||
public void ChangeOwner(IntPtr newOwner)
|
||||
{
|
||||
var _ = new WindowInteropHelper(this)
|
||||
{
|
||||
Owner = newOwner
|
||||
};
|
||||
foreach (var current in LoadedGlowWindows) current.ChangeOwner(newOwner);
|
||||
UpdateZOrderOfThisAndOwner();
|
||||
}
|
||||
|
||||
private static int PressedMouseButtons
|
||||
{
|
||||
get
|
||||
{
|
||||
var num = 0;
|
||||
if (InteropMethods.IsKeyPressed(1)) num |= 1;
|
||||
if (InteropMethods.IsKeyPressed(2)) num |= 2;
|
||||
if (InteropMethods.IsKeyPressed(4)) num |= 16;
|
||||
if (InteropMethods.IsKeyPressed(5)) num |= 32;
|
||||
if (InteropMethods.IsKeyPressed(6)) num |= 64;
|
||||
return num;
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerable<GlowEdge> LoadedGlowWindows => from w in _glowEdges where w != null select w;
|
||||
|
||||
protected virtual bool ShouldShowGlow
|
||||
{
|
||||
get
|
||||
{
|
||||
var handle = this.GetHandle();
|
||||
return InteropMethods.IsWindowVisible(handle) && !InteropMethods.IsIconic(handle) &&
|
||||
!InteropMethods.IsZoomed(handle) && ResizeMode != ResizeMode.NoResize;
|
||||
}
|
||||
}
|
||||
|
||||
private bool IsGlowVisible
|
||||
{
|
||||
get => _isGlowVisible;
|
||||
set
|
||||
{
|
||||
if (_isGlowVisible != value)
|
||||
{
|
||||
_isGlowVisible = value;
|
||||
for (var i = 0; i < _glowEdges.Length; i++)
|
||||
{
|
||||
GetOrCreateGlowWindow(i).IsVisible = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private GlowEdge GetOrCreateGlowWindow(int direction)
|
||||
{
|
||||
return _glowEdges[direction] ?? (_glowEdges[direction] = new GlowEdge(this, (Dock)direction)
|
||||
{
|
||||
ActiveGlowColor = ActiveGlowColor,
|
||||
InactiveGlowColor = InactiveGlowColor,
|
||||
IsActive = IsActive
|
||||
});
|
||||
}
|
||||
|
||||
private static void OnResizeModeChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var customChromeWindow = (GlowWindow)obj;
|
||||
customChromeWindow.UpdateGlowVisibility(false);
|
||||
}
|
||||
|
||||
private static void OnGlowColorChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
|
||||
{
|
||||
((GlowWindow)obj).UpdateGlowColors();
|
||||
}
|
||||
|
||||
private void UpdateGlowColors()
|
||||
{
|
||||
using (DeferGlowChanges())
|
||||
{
|
||||
foreach (var current in LoadedGlowWindows)
|
||||
{
|
||||
current.ActiveGlowColor = ActiveGlowColor;
|
||||
current.InactiveGlowColor = InactiveGlowColor;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateGlowVisibility(bool delayIfNecessary)
|
||||
{
|
||||
var shouldShowGlow = ShouldShowGlow;
|
||||
if (shouldShowGlow != IsGlowVisible)
|
||||
{
|
||||
if (SystemParameters.MinimizeAnimation && shouldShowGlow && delayIfNecessary)
|
||||
{
|
||||
if (_makeGlowVisibleTimer != null)
|
||||
{
|
||||
_makeGlowVisibleTimer.Stop();
|
||||
}
|
||||
else
|
||||
{
|
||||
_makeGlowVisibleTimer = new DispatcherTimer
|
||||
{
|
||||
Interval = TimeSpan.FromMilliseconds(200.0)
|
||||
};
|
||||
_makeGlowVisibleTimer.Tick += OnDelayedVisibilityTimerTick;
|
||||
}
|
||||
|
||||
_makeGlowVisibleTimer.Start();
|
||||
return;
|
||||
}
|
||||
|
||||
StopTimer();
|
||||
IsGlowVisible = shouldShowGlow;
|
||||
}
|
||||
}
|
||||
|
||||
private void StopTimer()
|
||||
{
|
||||
if (_makeGlowVisibleTimer != null)
|
||||
{
|
||||
_makeGlowVisibleTimer.Stop();
|
||||
_makeGlowVisibleTimer.Tick -= OnDelayedVisibilityTimerTick;
|
||||
_makeGlowVisibleTimer = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDelayedVisibilityTimerTick(object sender, EventArgs e)
|
||||
{
|
||||
StopTimer();
|
||||
UpdateGlowWindowPositions(false);
|
||||
}
|
||||
|
||||
private void UpdateGlowWindowPositions(bool delayIfNecessary)
|
||||
{
|
||||
using (DeferGlowChanges())
|
||||
{
|
||||
UpdateGlowVisibility(delayIfNecessary);
|
||||
foreach (var current in LoadedGlowWindows) current.UpdateWindowPos();
|
||||
}
|
||||
}
|
||||
|
||||
private IDisposable DeferGlowChanges() => new ChangeScope(this);
|
||||
|
||||
internal void EndDeferGlowChanges()
|
||||
{
|
||||
foreach (var current in LoadedGlowWindows) current.CommitChanges();
|
||||
}
|
||||
|
||||
private void UpdateGlowActiveState()
|
||||
{
|
||||
using (DeferGlowChanges())
|
||||
{
|
||||
foreach (var current in LoadedGlowWindows)
|
||||
{
|
||||
current.IsActive = IsActive;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void DestroyGlowWindows()
|
||||
{
|
||||
for (var i = 0; i < _glowEdges.Length; i++)
|
||||
{
|
||||
using (_glowEdges[i])
|
||||
{
|
||||
_glowEdges[i] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void WmActivate(IntPtr wParam, IntPtr lParam)
|
||||
{
|
||||
if (_ownerForActivate != IntPtr.Zero)
|
||||
InteropMethods.SendMessage(_ownerForActivate, InteropMethods.NOTIFYOWNERACTIVATE, wParam, lParam);
|
||||
}
|
||||
|
||||
private void WmWindowPosChanging(IntPtr hwnd, IntPtr lParam)
|
||||
{
|
||||
var windowpos = (InteropValues.WINDOWPOS)Marshal.PtrToStructure(lParam, typeof(InteropValues.WINDOWPOS));
|
||||
if ((windowpos.flags & 2u) == 0u && (windowpos.flags & 1u) == 0u && windowpos.cx > 0 && windowpos.cy > 0)
|
||||
{
|
||||
var rect = new Rect(windowpos.x, windowpos.y, windowpos.cx, windowpos.cy);
|
||||
rect = rect.DeviceToLogicalUnits();
|
||||
if (_useLogicalSizeForRestore)
|
||||
{
|
||||
rect = _logicalSizeForRestore;
|
||||
_logicalSizeForRestore = Rect.Empty;
|
||||
_useLogicalSizeForRestore = false;
|
||||
}
|
||||
|
||||
var logicalRect = GetOnScreenPosition(rect);
|
||||
logicalRect = logicalRect.LogicalToDeviceUnits();
|
||||
windowpos.x = (int)logicalRect.X;
|
||||
windowpos.y = (int)logicalRect.Y;
|
||||
Marshal.StructureToPtr(windowpos, lParam, true);
|
||||
}
|
||||
}
|
||||
|
||||
private static InteropValues.RECT GetClientRectRelativeToWindowRect(IntPtr hWnd)
|
||||
{
|
||||
InteropMethods.GetWindowRect(hWnd, out var rect);
|
||||
InteropMethods.GetClientRect(hWnd, out var result);
|
||||
var point = new InteropValues.POINT
|
||||
{
|
||||
X = 0,
|
||||
Y = 0
|
||||
};
|
||||
InteropMethods.ClientToScreen(hWnd, ref point);
|
||||
result.Offset(point.X - rect.Left, point.Y - rect.Top);
|
||||
return result;
|
||||
}
|
||||
|
||||
private void UpdateMaximizedClipRegion(IntPtr hWnd)
|
||||
{
|
||||
var clientRectRelativeToWindowRect = GetClientRectRelativeToWindowRect(hWnd);
|
||||
if (_isNonClientStripVisible) clientRectRelativeToWindowRect.Bottom++;
|
||||
|
||||
var hRgn = InteropMethods.CreateRectRgnIndirect(ref clientRectRelativeToWindowRect);
|
||||
InteropMethods.SetWindowRgn(hWnd, hRgn, InteropMethods.IsWindowVisible(hWnd));
|
||||
}
|
||||
|
||||
private IntPtr ComputeRoundRectRegion(int left, int top, int width, int height, int cornerRadius)
|
||||
{
|
||||
var nWidthEllipse = (int)(2 * cornerRadius * DpiHelper.LogicalToDeviceUnitsScalingFactorX);
|
||||
var nHeightEllipse = (int)(2 * cornerRadius * DpiHelper.LogicalToDeviceUnitsScalingFactorY);
|
||||
return InteropMethods.CreateRoundRectRgn(left, top, left + width + 1, top + height + 1, nWidthEllipse,
|
||||
nHeightEllipse);
|
||||
}
|
||||
|
||||
protected void SetRoundRect(IntPtr hWnd, int width, int height)
|
||||
{
|
||||
var hRgn = ComputeRoundRectRegion(0, 0, width, height, 0);
|
||||
InteropMethods.SetWindowRgn(hWnd, hRgn, InteropMethods.IsWindowVisible(hWnd));
|
||||
}
|
||||
|
||||
protected virtual bool UpdateClipRegionCore(IntPtr hWnd, int showCmd, ClipRegionChangeType changeType, Int32Rect currentBounds)
|
||||
{
|
||||
if (showCmd == 3)
|
||||
{
|
||||
UpdateMaximizedClipRegion(hWnd);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (changeType == ClipRegionChangeType.FromSize || changeType == ClipRegionChangeType.FromPropertyChange ||
|
||||
_lastWindowPlacement != showCmd)
|
||||
{
|
||||
SetRoundRect(hWnd, currentBounds.Width, currentBounds.Height);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void UpdateClipRegion(IntPtr hWnd, InteropValues.WINDOWPLACEMENT placement, ClipRegionChangeType changeType,
|
||||
InteropValues.RECT currentBounds)
|
||||
{
|
||||
UpdateClipRegionCore(hWnd, placement.showCmd, changeType, currentBounds.ToInt32Rect());
|
||||
_lastWindowPlacement = placement.showCmd;
|
||||
}
|
||||
|
||||
protected virtual void OnWindowPosChanged(IntPtr hWnd, int showCmd, Int32Rect rcNormalPosition)
|
||||
{
|
||||
}
|
||||
|
||||
private void UpdateZOrderOfOwner(IntPtr hwndOwner)
|
||||
{
|
||||
var lastOwnedWindow = IntPtr.Zero;
|
||||
InteropMethods.EnumThreadWindows(InteropMethods.GetCurrentThreadId(), delegate (IntPtr hwnd, IntPtr lParam)
|
||||
{
|
||||
if (InteropMethods.GetWindow(hwnd, 4) == hwndOwner) lastOwnedWindow = hwnd;
|
||||
return true;
|
||||
}, IntPtr.Zero);
|
||||
|
||||
if (lastOwnedWindow != IntPtr.Zero && InteropMethods.GetWindow(hwndOwner, 3) != lastOwnedWindow)
|
||||
InteropMethods.SetWindowPos(hwndOwner, lastOwnedWindow, 0, 0, 0, 0, 19);
|
||||
}
|
||||
|
||||
private void UpdateZOrderOfThisAndOwner()
|
||||
{
|
||||
if (_updatingZOrder) return;
|
||||
try
|
||||
{
|
||||
_updatingZOrder = true;
|
||||
var windowInteropHelper = new WindowInteropHelper(this);
|
||||
var handle = windowInteropHelper.Handle;
|
||||
foreach (var current in LoadedGlowWindows)
|
||||
{
|
||||
var window = InteropMethods.GetWindow(current.Handle, 3);
|
||||
if (window != handle) InteropMethods.SetWindowPos(current.Handle, handle, 0, 0, 0, 0, 19);
|
||||
handle = current.Handle;
|
||||
}
|
||||
|
||||
var owner = windowInteropHelper.Owner;
|
||||
if (owner != IntPtr.Zero) UpdateZOrderOfOwner(owner);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_updatingZOrder = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void WmWindowPosChanged(IntPtr hWnd, IntPtr lParam)
|
||||
{
|
||||
try
|
||||
{
|
||||
var windowpos = (InteropValues.WINDOWPOS)Marshal.PtrToStructure(lParam, typeof(InteropValues.WINDOWPOS));
|
||||
var windowPlacement = InteropMethods.GetWindowPlacement(hWnd);
|
||||
var currentBounds = new InteropValues.RECT(windowpos.x, windowpos.y, windowpos.x + windowpos.cx,
|
||||
windowpos.y + windowpos.cy);
|
||||
if ((windowpos.flags & 1u) != 1u)
|
||||
{
|
||||
UpdateClipRegion(hWnd, windowPlacement, ClipRegionChangeType.FromSize, currentBounds);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((windowpos.flags & 2u) != 2u)
|
||||
UpdateClipRegion(hWnd, windowPlacement, ClipRegionChangeType.FromPosition, currentBounds);
|
||||
}
|
||||
|
||||
OnWindowPosChanged(hWnd, windowPlacement.showCmd, windowPlacement.rcNormalPosition.ToInt32Rect());
|
||||
UpdateGlowWindowPositions((windowpos.flags & 64u) == 0u);
|
||||
UpdateZOrderOfThisAndOwner();
|
||||
}
|
||||
catch (Win32Exception)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
internal Rect GetOnScreenPosition(Rect floatRect)
|
||||
{
|
||||
var result = floatRect;
|
||||
floatRect = floatRect.LogicalToDeviceUnits();
|
||||
ScreenHelper.FindMaximumSingleMonitorRectangle(floatRect, out _, out var rect2);
|
||||
if (!floatRect.IntersectsWith(rect2))
|
||||
{
|
||||
ScreenHelper.FindMonitorRectsFromPoint(InteropMethods.GetCursorPos(), out _, out rect2);
|
||||
rect2 = rect2.DeviceToLogicalUnits();
|
||||
if (result.Width > rect2.Width) result.Width = rect2.Width;
|
||||
if (result.Height > rect2.Height) result.Height = rect2.Height;
|
||||
if (rect2.Right <= result.X) result.X = rect2.Right - result.Width;
|
||||
if (rect2.Left > result.X + result.Width) result.X = rect2.Left;
|
||||
if (rect2.Bottom <= result.Y) result.Y = rect2.Bottom - result.Height;
|
||||
if (rect2.Top > result.Y + result.Height) result.Y = rect2.Top;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static InteropValues.MONITORINFO MonitorInfoFromWindow(IntPtr hWnd)
|
||||
{
|
||||
var hMonitor = InteropMethods.MonitorFromWindow(hWnd, 2);
|
||||
var result = default(InteropValues.MONITORINFO);
|
||||
result.cbSize = (uint)Marshal.SizeOf(typeof(InteropValues.MONITORINFO));
|
||||
InteropMethods.GetMonitorInfo(hMonitor, ref result);
|
||||
return result;
|
||||
}
|
||||
|
||||
private InteropValues.WINDOWINFO GetWindowInfo(IntPtr hWnd)
|
||||
{
|
||||
var windowInfo = default(InteropValues.WINDOWINFO);
|
||||
windowInfo.cbSize = Marshal.SizeOf(windowInfo);
|
||||
InteropMethods.GetWindowInfo(hWnd, ref windowInfo);
|
||||
return windowInfo;
|
||||
}
|
||||
|
||||
private IntPtr WmNcCalcSize(IntPtr hWnd, IntPtr wParam, IntPtr lParam, ref bool handled)
|
||||
{
|
||||
_isNonClientStripVisible = false;
|
||||
var windowPlacement = InteropMethods.GetWindowPlacement(hWnd);
|
||||
var flag = windowPlacement.showCmd == 3;
|
||||
if (flag)
|
||||
{
|
||||
var rect = (InteropValues.RECT)Marshal.PtrToStructure(lParam, typeof(InteropValues.RECT));
|
||||
InteropMethods.DefWindowProc(hWnd, 131, wParam, lParam);
|
||||
var rect2 = (InteropValues.RECT)Marshal.PtrToStructure(lParam, typeof(InteropValues.RECT));
|
||||
var monitorinfo = MonitorInfoFromWindow(hWnd);
|
||||
if (monitorinfo.rcMonitor.Height == monitorinfo.rcWork.Height &&
|
||||
monitorinfo.rcMonitor.Width == monitorinfo.rcWork.Width)
|
||||
{
|
||||
_isNonClientStripVisible = true;
|
||||
rect2.Bottom--;
|
||||
}
|
||||
|
||||
rect2.Top = rect.Top + (int)GetWindowInfo(hWnd).cyWindowBorders;
|
||||
Marshal.StructureToPtr(rect2, lParam, true);
|
||||
}
|
||||
|
||||
handled = true;
|
||||
return IntPtr.Zero;
|
||||
}
|
||||
|
||||
private IntPtr WmNcHitTest(IntPtr hWnd, IntPtr lParam, ref bool handled)
|
||||
{
|
||||
if (PresentationSource.FromDependencyObject(this) == null) return new IntPtr(0);
|
||||
|
||||
var point = new Point(InteropMethods.GetXLParam(lParam.ToInt32()),
|
||||
InteropMethods.GetYLParam(lParam.ToInt32()));
|
||||
var point2 = PointFromScreen(point);
|
||||
DependencyObject visualHit = null;
|
||||
VisualHelper.HitTestVisibleElements(this, delegate (HitTestResult target)
|
||||
{
|
||||
visualHit = target.VisualHit;
|
||||
return HitTestResultBehavior.Stop;
|
||||
}, new PointHitTestParameters(point2));
|
||||
|
||||
var num = 0;
|
||||
while (visualHit != null)
|
||||
{
|
||||
//var nonClientArea = visualHit as INonClientArea;
|
||||
//if (nonClientArea != null)
|
||||
//{
|
||||
// num = nonClientArea.HitTest(point);
|
||||
// if (num != 0) break;
|
||||
//}
|
||||
|
||||
visualHit = visualHit.GetVisualOrLogicalParent();
|
||||
}
|
||||
|
||||
if (num == 0) num = 1;
|
||||
handled = true;
|
||||
return new IntPtr(num);
|
||||
}
|
||||
|
||||
private IntPtr WmNcActivate(IntPtr hWnd, IntPtr wParam, IntPtr lParam, ref bool handled)
|
||||
{
|
||||
handled = true;
|
||||
return InteropMethods.DefWindowProc(hWnd, 134, wParam, InteropMethods.HRGN_NONE);
|
||||
}
|
||||
|
||||
private static void RaiseNonClientMouseMessageAsClient(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam)
|
||||
{
|
||||
var point = new InteropValues.POINT
|
||||
{
|
||||
X = InteropMethods.GetXLParam(lParam.ToInt32()),
|
||||
Y = InteropMethods.GetYLParam(lParam.ToInt32())
|
||||
};
|
||||
|
||||
InteropMethods.ScreenToClient(hWnd, ref point);
|
||||
InteropMethods.SendMessage(hWnd, msg + 513 - 161, new IntPtr(PressedMouseButtons),
|
||||
InteropMethods.MakeParam(point.X, point.Y));
|
||||
}
|
||||
|
||||
private bool IsAeroSnappedToMonitor(IntPtr hWnd)
|
||||
{
|
||||
var monitorinfo = MonitorInfoFromWindow(hWnd);
|
||||
var logicalRect = new Rect(Left, Top, Width, Height);
|
||||
logicalRect = logicalRect.LogicalToDeviceUnits();
|
||||
return MathHelper.AreClose(monitorinfo.rcWork.Height, logicalRect.Height) && MathHelper.AreClose(monitorinfo.rcWork.Top, logicalRect.Top);
|
||||
}
|
||||
|
||||
private void WmSysCommand(IntPtr hWnd, IntPtr wParam, IntPtr lParam)
|
||||
{
|
||||
var num = InteropMethods.GET_SC_WPARAM(wParam);
|
||||
if (num == 61456)
|
||||
InteropMethods.RedrawWindow(hWnd, IntPtr.Zero, IntPtr.Zero,
|
||||
InteropValues.RedrawWindowFlags.Invalidate | InteropValues.RedrawWindowFlags.NoChildren |
|
||||
InteropValues.RedrawWindowFlags.UpdateNow | InteropValues.RedrawWindowFlags.Frame);
|
||||
if ((num == 61488 || num == 61472 || num == 61456 || num == 61440) && WindowState == WindowState.Normal &&
|
||||
!IsAeroSnappedToMonitor(hWnd)) _logicalSizeForRestore = new Rect(Left, Top, Width, Height);
|
||||
if (num == 61456 && WindowState == WindowState.Maximized && _logicalSizeForRestore == Rect.Empty)
|
||||
_logicalSizeForRestore = new Rect(Left, Top, Width, Height);
|
||||
if (num == 61728 && WindowState != WindowState.Minimized && _logicalSizeForRestore.Width > 0.0 &&
|
||||
_logicalSizeForRestore.Height > 0.0)
|
||||
{
|
||||
Left = _logicalSizeForRestore.Left;
|
||||
Top = _logicalSizeForRestore.Top;
|
||||
Width = _logicalSizeForRestore.Width;
|
||||
Height = _logicalSizeForRestore.Height;
|
||||
_useLogicalSizeForRestore = true;
|
||||
}
|
||||
}
|
||||
|
||||
private IntPtr CallDefWindowProcWithoutVisibleStyle(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
|
||||
{
|
||||
var flag = VisualHelper.ModifyStyle(hWnd, 268435456, 0);
|
||||
var result = InteropMethods.DefWindowProc(hWnd, msg, wParam, lParam);
|
||||
if (flag) VisualHelper.ModifyStyle(hWnd, 0, 268435456);
|
||||
handled = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
protected virtual IntPtr HwndSourceHook(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
|
||||
{
|
||||
if (msg <= 71)
|
||||
{
|
||||
if (msg == 6)
|
||||
{
|
||||
WmActivate(wParam, lParam);
|
||||
goto IL_11C;
|
||||
}
|
||||
|
||||
if (msg != 12)
|
||||
switch (msg)
|
||||
{
|
||||
case 70:
|
||||
WmWindowPosChanging(hWnd, lParam);
|
||||
goto IL_11C;
|
||||
case 71:
|
||||
WmWindowPosChanged(hWnd, lParam);
|
||||
goto IL_11C;
|
||||
default:
|
||||
goto IL_11C;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (msg <= 166)
|
||||
switch (msg)
|
||||
{
|
||||
case 128:
|
||||
break;
|
||||
case 129:
|
||||
case 130:
|
||||
goto IL_11C;
|
||||
case 131:
|
||||
return WmNcCalcSize(hWnd, wParam, lParam, ref handled);
|
||||
case 132:
|
||||
return WmNcHitTest(hWnd, lParam, ref handled);
|
||||
//case 133:
|
||||
// return WmNcPaint(hWnd, wParam, lParam, ref handled);
|
||||
case 134:
|
||||
return WmNcActivate(hWnd, wParam, lParam, ref handled);
|
||||
default:
|
||||
switch (msg)
|
||||
{
|
||||
case 164:
|
||||
case 165:
|
||||
case 166:
|
||||
RaiseNonClientMouseMessageAsClient(hWnd, msg, wParam, lParam);
|
||||
handled = true;
|
||||
goto IL_11C;
|
||||
default:
|
||||
goto IL_11C;
|
||||
}
|
||||
}
|
||||
else
|
||||
switch (msg)
|
||||
{
|
||||
case 174:
|
||||
case 175:
|
||||
handled = true;
|
||||
goto IL_11C;
|
||||
default:
|
||||
if (msg != 274) goto IL_11C;
|
||||
WmSysCommand(hWnd, wParam, lParam);
|
||||
goto IL_11C;
|
||||
}
|
||||
}
|
||||
|
||||
return CallDefWindowProcWithoutVisibleStyle(hWnd, msg, wParam, lParam, ref handled);
|
||||
IL_11C:
|
||||
return IntPtr.Zero;
|
||||
}
|
||||
|
||||
private void CreateGlowWindowHandles()
|
||||
{
|
||||
for (var i = 0; i < _glowEdges.Length; i++) GetOrCreateGlowWindow(i).EnsureHandle();
|
||||
}
|
||||
|
||||
protected override void OnActivated(EventArgs e)
|
||||
{
|
||||
UpdateGlowActiveState();
|
||||
base.OnActivated(e);
|
||||
}
|
||||
|
||||
protected override void OnDeactivated(EventArgs e)
|
||||
{
|
||||
UpdateGlowActiveState();
|
||||
base.OnDeactivated(e);
|
||||
}
|
||||
|
||||
protected override void OnClosed(EventArgs e)
|
||||
{
|
||||
StopTimer();
|
||||
DestroyGlowWindows();
|
||||
base.OnClosed(e);
|
||||
}
|
||||
|
||||
protected override void OnSourceInitialized(EventArgs e)
|
||||
{
|
||||
var hwndSource = HwndSource.FromHwnd(new WindowInteropHelper(this).Handle);
|
||||
if (hwndSource != null)
|
||||
{
|
||||
hwndSource.AddHook(HwndSourceHook);
|
||||
CreateGlowWindowHandles();
|
||||
}
|
||||
|
||||
base.OnSourceInitialized(e);
|
||||
}
|
||||
|
||||
protected enum ClipRegionChangeType
|
||||
{
|
||||
FromSize,
|
||||
FromPosition,
|
||||
FromPropertyChange,
|
||||
FromUndockSingleTab
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -92,6 +92,11 @@ namespace HandyControl.Controls
|
||||
|
||||
private ResizeMode _tempResizeMode;
|
||||
|
||||
static Window()
|
||||
{
|
||||
StyleProperty.OverrideMetadata(typeof(Window), new FrameworkPropertyMetadata(Application.Current.FindResource(ResourceToken.WindowWin10)));
|
||||
}
|
||||
|
||||
public Window()
|
||||
{
|
||||
#if netle40
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
using System;
|
||||
|
||||
namespace HandyControl.Data
|
||||
{
|
||||
public class DisposableObject : IDisposable
|
||||
{
|
||||
private EventHandler _disposing;
|
||||
|
||||
public bool IsDisposed { get; private set; }
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
~DisposableObject()
|
||||
{
|
||||
Dispose(false);
|
||||
}
|
||||
|
||||
public event EventHandler Disposing
|
||||
{
|
||||
add
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
_disposing += value;
|
||||
}
|
||||
remove
|
||||
{
|
||||
_disposing -= value;
|
||||
}
|
||||
}
|
||||
|
||||
protected void ThrowIfDisposed()
|
||||
{
|
||||
if (IsDisposed) throw new ObjectDisposedException(GetType().Name);
|
||||
}
|
||||
|
||||
protected void Dispose(bool disposing)
|
||||
{
|
||||
if (IsDisposed) return;
|
||||
|
||||
try
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
_disposing?.Invoke(this, EventArgs.Empty);
|
||||
_disposing = null;
|
||||
DisposeManagedResources();
|
||||
}
|
||||
|
||||
DisposeNativeResources();
|
||||
}
|
||||
finally
|
||||
{
|
||||
IsDisposed = true;
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void DisposeManagedResources()
|
||||
{
|
||||
}
|
||||
|
||||
protected virtual void DisposeNativeResources()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using HandyControl.Controls;
|
||||
|
||||
namespace HandyControl.Data
|
||||
{
|
||||
internal class ChangeScope : DisposableObject
|
||||
{
|
||||
private readonly GlowWindow _window;
|
||||
|
||||
public ChangeScope(GlowWindow window)
|
||||
{
|
||||
_window = window;
|
||||
_window.DeferGlowChangesCount++;
|
||||
}
|
||||
|
||||
protected override void DisposeManagedResources()
|
||||
{
|
||||
_window.DeferGlowChangesCount--;
|
||||
if (_window.DeferGlowChangesCount == 0) _window.EndDeferGlowChanges();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using HandyControl.Tools.Interop;
|
||||
|
||||
namespace HandyControl.Data
|
||||
{
|
||||
internal class GlowBitmap : DisposableObject
|
||||
{
|
||||
internal const int GlowBitmapPartCount = 16;
|
||||
|
||||
private const int BytesPerPixelBgra32 = 4;
|
||||
|
||||
private static readonly CachedBitmapInfo[] _transparencyMasks = new CachedBitmapInfo[GlowBitmapPartCount];
|
||||
|
||||
private readonly InteropValues.BITMAPINFO _bitmapInfo;
|
||||
|
||||
private readonly IntPtr _pbits;
|
||||
|
||||
internal GlowBitmap(IntPtr hdcScreen, int width, int height)
|
||||
{
|
||||
_bitmapInfo.biSize = Marshal.SizeOf(typeof(InteropValues.BITMAPINFOHEADER));
|
||||
_bitmapInfo.biPlanes = 1;
|
||||
_bitmapInfo.biBitCount = 32;
|
||||
_bitmapInfo.biCompression = 0;
|
||||
_bitmapInfo.biXPelsPerMeter = 0;
|
||||
_bitmapInfo.biYPelsPerMeter = 0;
|
||||
_bitmapInfo.biWidth = width;
|
||||
_bitmapInfo.biHeight = -height;
|
||||
|
||||
Handle = InteropMethods.CreateDIBSection(
|
||||
hdcScreen,
|
||||
ref _bitmapInfo,
|
||||
0u,
|
||||
out _pbits,
|
||||
IntPtr.Zero,
|
||||
0u);
|
||||
}
|
||||
|
||||
internal IntPtr Handle { get; }
|
||||
|
||||
internal IntPtr DIBits => _pbits;
|
||||
|
||||
internal int Width => _bitmapInfo.biWidth;
|
||||
|
||||
internal int Height => -_bitmapInfo.biHeight;
|
||||
|
||||
protected override void DisposeNativeResources() => InteropMethods.DeleteObject(Handle);
|
||||
|
||||
private static byte PremultiplyAlpha(byte channel, byte alpha) => (byte)(channel * alpha / 255.0);
|
||||
|
||||
internal static GlowBitmap Create(GlowDrawingContext drawingContext, GlowBitmapPart bitmapPart, Color color)
|
||||
{
|
||||
var orCreateAlphaMask =
|
||||
GetOrCreateAlphaMask(bitmapPart);
|
||||
|
||||
var glowBitmap =
|
||||
new GlowBitmap(
|
||||
drawingContext.ScreenDC,
|
||||
orCreateAlphaMask.Width,
|
||||
orCreateAlphaMask.Height);
|
||||
|
||||
for (var i = 0; i < orCreateAlphaMask.DIBits.Length; i += BytesPerPixelBgra32)
|
||||
{
|
||||
var b = orCreateAlphaMask.DIBits[i + 3];
|
||||
var val = PremultiplyAlpha(color.R, b);
|
||||
var val2 = PremultiplyAlpha(color.G, b);
|
||||
var val3 = PremultiplyAlpha(color.B, b);
|
||||
Marshal.WriteByte(glowBitmap.DIBits, i, val3);
|
||||
Marshal.WriteByte(glowBitmap.DIBits, i + 1, val2);
|
||||
Marshal.WriteByte(glowBitmap.DIBits, i + 2, val);
|
||||
Marshal.WriteByte(glowBitmap.DIBits, i + 3, b);
|
||||
}
|
||||
|
||||
return glowBitmap;
|
||||
}
|
||||
|
||||
private static CachedBitmapInfo GetOrCreateAlphaMask(GlowBitmapPart bitmapPart)
|
||||
{
|
||||
if (_transparencyMasks[(int)bitmapPart] == null)
|
||||
{
|
||||
var bitmapImage = new BitmapImage(new Uri($"pack://application:,,,/HandyControl;Component/Resources/Images/GlowWindow/{bitmapPart}.png"));
|
||||
|
||||
var array = new byte[BytesPerPixelBgra32 * bitmapImage.PixelWidth * bitmapImage.PixelHeight];
|
||||
var stride = BytesPerPixelBgra32 * bitmapImage.PixelWidth;
|
||||
bitmapImage.CopyPixels(array, stride, 0);
|
||||
|
||||
_transparencyMasks[(int)bitmapPart] =
|
||||
new CachedBitmapInfo(
|
||||
array,
|
||||
bitmapImage.PixelWidth,
|
||||
bitmapImage.PixelHeight);
|
||||
}
|
||||
|
||||
return _transparencyMasks[(int)bitmapPart];
|
||||
}
|
||||
|
||||
private sealed class CachedBitmapInfo
|
||||
{
|
||||
internal readonly byte[] DIBits;
|
||||
internal readonly int Height;
|
||||
internal readonly int Width;
|
||||
|
||||
internal CachedBitmapInfo(byte[] diBits, int width, int height)
|
||||
{
|
||||
Width = width;
|
||||
Height = height;
|
||||
DIBits = diBits;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
namespace HandyControl.Data
|
||||
{
|
||||
internal enum GlowBitmapPart
|
||||
{
|
||||
CornerTopLeft,
|
||||
CornerTopRight,
|
||||
CornerBottomLeft,
|
||||
CornerBottomRight,
|
||||
TopLeft,
|
||||
Top,
|
||||
TopRight,
|
||||
LeftTop,
|
||||
Left,
|
||||
LeftBottom,
|
||||
BottomLeft,
|
||||
Bottom,
|
||||
BottomRight,
|
||||
RightTop,
|
||||
Right,
|
||||
RightBottom
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
using System;
|
||||
using HandyControl.Tools.Interop;
|
||||
|
||||
namespace HandyControl.Data
|
||||
{
|
||||
internal class GlowDrawingContext : DisposableObject
|
||||
{
|
||||
private readonly GlowBitmap _windowBitmap;
|
||||
|
||||
internal InteropValues.BLENDFUNCTION Blend;
|
||||
|
||||
internal GlowDrawingContext(int width, int height)
|
||||
{
|
||||
ScreenDC = InteropMethods.GetDC(IntPtr.Zero);
|
||||
if (ScreenDC == IntPtr.Zero) return;
|
||||
WindowDC = InteropMethods.CreateCompatibleDC(ScreenDC);
|
||||
if (WindowDC == IntPtr.Zero) return;
|
||||
BackgroundDC = InteropMethods.CreateCompatibleDC(ScreenDC);
|
||||
if (BackgroundDC == IntPtr.Zero) return;
|
||||
Blend.BlendOp = 0;
|
||||
Blend.BlendFlags = 0;
|
||||
Blend.SourceConstantAlpha = 255;
|
||||
Blend.AlphaFormat = 1;
|
||||
_windowBitmap = new GlowBitmap(ScreenDC, width, height);
|
||||
InteropMethods.SelectObject(WindowDC, _windowBitmap.Handle);
|
||||
}
|
||||
|
||||
internal bool IsInitialized =>
|
||||
ScreenDC != IntPtr.Zero && WindowDC != IntPtr.Zero &&
|
||||
BackgroundDC != IntPtr.Zero && _windowBitmap != null;
|
||||
|
||||
internal IntPtr ScreenDC { get; }
|
||||
|
||||
internal IntPtr WindowDC { get; }
|
||||
|
||||
internal IntPtr BackgroundDC { get; }
|
||||
|
||||
internal int Width => _windowBitmap.Width;
|
||||
|
||||
internal int Height => _windowBitmap.Height;
|
||||
|
||||
protected override void DisposeManagedResources() => _windowBitmap.Dispose();
|
||||
|
||||
protected override void DisposeNativeResources()
|
||||
{
|
||||
if (ScreenDC != IntPtr.Zero) InteropMethods.ReleaseDC(IntPtr.Zero, ScreenDC);
|
||||
if (WindowDC != IntPtr.Zero) InteropMethods.DeleteDC(WindowDC);
|
||||
if (BackgroundDC != IntPtr.Zero) InteropMethods.DeleteDC(BackgroundDC);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,587 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Interop;
|
||||
using System.Windows.Media;
|
||||
using HandyControl.Controls;
|
||||
using HandyControl.Tools.Interop;
|
||||
|
||||
namespace HandyControl.Data
|
||||
{
|
||||
internal class GlowEdge : HwndWrapper
|
||||
{
|
||||
private const string GlowEdgeClassName = "HandyControlGlowEdge";
|
||||
|
||||
private const int GlowDepth = 9;
|
||||
|
||||
private const int CornerGripThickness = 18;
|
||||
|
||||
private static ushort _sharedWindowClassAtom;
|
||||
|
||||
// ReSharper disable once NotAccessedField.Local
|
||||
private static InteropValues.WndProc _sharedWndProc;
|
||||
|
||||
private readonly GlowBitmap[] _activeGlowBitmaps = new GlowBitmap[16];
|
||||
|
||||
private readonly GlowBitmap[] _inactiveGlowBitmaps = new GlowBitmap[16];
|
||||
|
||||
private readonly Dock _orientation;
|
||||
|
||||
private readonly GlowWindow _targetWindow;
|
||||
|
||||
private Color _activeGlowColor = Colors.Transparent;
|
||||
|
||||
private int _height;
|
||||
|
||||
private Color _inactiveGlowColor = Colors.Transparent;
|
||||
|
||||
private FieldInvalidationTypes _invalidatedValues;
|
||||
|
||||
private bool _isActive;
|
||||
|
||||
private bool _isVisible;
|
||||
|
||||
private int _left;
|
||||
|
||||
private bool _pendingDelayRender;
|
||||
|
||||
private int _top;
|
||||
|
||||
private int _width;
|
||||
|
||||
internal static long CreatedGlowEdges { get; private set; }
|
||||
|
||||
internal static long DisposedGlowEdges { get; private set; }
|
||||
|
||||
internal GlowEdge(GlowWindow owner, Dock orientation)
|
||||
{
|
||||
_targetWindow = owner ?? throw new ArgumentNullException(nameof(owner));
|
||||
_orientation = orientation;
|
||||
CreatedGlowEdges += 1L;
|
||||
}
|
||||
|
||||
private bool IsDeferringChanges => _targetWindow.DeferGlowChangesCount > 0;
|
||||
|
||||
private static ushort SharedWindowClassAtom
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_sharedWindowClassAtom == 0)
|
||||
{
|
||||
var wndclass = default(InteropValues.WNDCLASS);
|
||||
|
||||
wndclass.cbClsExtra = 0;
|
||||
wndclass.cbWndExtra = 0;
|
||||
wndclass.hbrBackground = IntPtr.Zero;
|
||||
wndclass.hCursor = IntPtr.Zero;
|
||||
wndclass.hIcon = IntPtr.Zero;
|
||||
wndclass.lpfnWndProc = _sharedWndProc = InteropMethods.DefWindowProc;
|
||||
wndclass.lpszClassName = GlowEdgeClassName;
|
||||
wndclass.lpszMenuName = null;
|
||||
wndclass.style = 0u;
|
||||
|
||||
_sharedWindowClassAtom = InteropMethods.RegisterClass(ref wndclass);
|
||||
}
|
||||
|
||||
return _sharedWindowClassAtom;
|
||||
}
|
||||
}
|
||||
|
||||
internal bool IsVisible
|
||||
{
|
||||
get => _isVisible;
|
||||
set => UpdateProperty(ref _isVisible, value, FieldInvalidationTypes.Render | FieldInvalidationTypes.Visibility);
|
||||
}
|
||||
|
||||
internal int Left
|
||||
{
|
||||
get => _left;
|
||||
set => UpdateProperty(ref _left, value, FieldInvalidationTypes.Location);
|
||||
}
|
||||
|
||||
internal int Top
|
||||
{
|
||||
get => _top;
|
||||
set => UpdateProperty(ref _top, value, FieldInvalidationTypes.Location);
|
||||
}
|
||||
|
||||
internal int Width
|
||||
{
|
||||
get => _width;
|
||||
set => UpdateProperty( ref _width, value, FieldInvalidationTypes.Size | FieldInvalidationTypes.Render);
|
||||
}
|
||||
|
||||
internal int Height
|
||||
{
|
||||
get => _height;
|
||||
set => UpdateProperty(ref _height, value, FieldInvalidationTypes.Size | FieldInvalidationTypes.Render);
|
||||
}
|
||||
|
||||
internal bool IsActive
|
||||
{
|
||||
get => _isActive;
|
||||
set => UpdateProperty(ref _isActive, value, FieldInvalidationTypes.Render);
|
||||
}
|
||||
|
||||
internal Color ActiveGlowColor
|
||||
{
|
||||
get => _activeGlowColor;
|
||||
set => UpdateProperty(ref _activeGlowColor, value, FieldInvalidationTypes.ActiveColor | FieldInvalidationTypes.Render);
|
||||
}
|
||||
|
||||
internal Color InactiveGlowColor
|
||||
{
|
||||
get => _inactiveGlowColor;
|
||||
set => UpdateProperty(ref _inactiveGlowColor, value, FieldInvalidationTypes.InactiveColor | FieldInvalidationTypes.Render);
|
||||
}
|
||||
|
||||
private IntPtr TargetWindowHandle => new WindowInteropHelper(_targetWindow).Handle;
|
||||
|
||||
protected override bool IsWindowSubclassed => true;
|
||||
|
||||
private bool IsPositionValid => (_invalidatedValues & (FieldInvalidationTypes.Location | FieldInvalidationTypes.Size | FieldInvalidationTypes.Visibility)) == FieldInvalidationTypes.None;
|
||||
|
||||
private void UpdateProperty<T>(ref T field, T value, FieldInvalidationTypes invalidatedValues) where T : struct
|
||||
{
|
||||
if (!field.Equals(value))
|
||||
{
|
||||
field = value;
|
||||
_invalidatedValues |= invalidatedValues;
|
||||
if (!IsDeferringChanges) CommitChanges();
|
||||
}
|
||||
}
|
||||
|
||||
protected override ushort CreateWindowClassCore() => SharedWindowClassAtom;
|
||||
|
||||
protected override void DestroyWindowClassCore()
|
||||
{
|
||||
}
|
||||
|
||||
protected override IntPtr CreateWindowCore()
|
||||
{
|
||||
return InteropMethods.CreateWindowEx(
|
||||
524416,
|
||||
new IntPtr(WindowClassAtom),
|
||||
string.Empty,
|
||||
-2046820352,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
new WindowInteropHelper(_targetWindow).Owner,
|
||||
IntPtr.Zero,
|
||||
IntPtr.Zero,
|
||||
IntPtr.Zero);
|
||||
}
|
||||
|
||||
internal void ChangeOwner(IntPtr newOwner) => InteropMethods.SetWindowLongPtr(Handle, InteropValues.GWLP.HWNDPARENT, newOwner);
|
||||
|
||||
protected override IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam)
|
||||
{
|
||||
if (msg <= 70)
|
||||
{
|
||||
if (msg == 6) return IntPtr.Zero;
|
||||
if (msg == 70)
|
||||
{
|
||||
var windowpos = (InteropValues.WINDOWPOS)Marshal.PtrToStructure(lParam, typeof(InteropValues.WINDOWPOS));
|
||||
windowpos.flags |= 16u;
|
||||
Marshal.StructureToPtr(windowpos, lParam, true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (msg != 126)
|
||||
{
|
||||
if (msg == 132) return new IntPtr(WmNcHitTest(lParam));
|
||||
switch (msg)
|
||||
{
|
||||
case 161:
|
||||
case 163:
|
||||
case 164:
|
||||
case 166:
|
||||
case 167:
|
||||
case 169:
|
||||
case 171:
|
||||
case 173:
|
||||
{
|
||||
var targetWindowHandle = TargetWindowHandle;
|
||||
InteropMethods.SendMessage(targetWindowHandle, 6, new IntPtr(2), IntPtr.Zero);
|
||||
InteropMethods.SendMessage(targetWindowHandle, msg, wParam, IntPtr.Zero);
|
||||
return IntPtr.Zero;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (IsVisible) RenderLayeredWindow();
|
||||
}
|
||||
}
|
||||
|
||||
return base.WndProc(hwnd, msg, wParam, lParam);
|
||||
}
|
||||
|
||||
private int WmNcHitTest(IntPtr lParam)
|
||||
{
|
||||
var xLParam = InteropMethods.GetXLParam(lParam.ToInt32());
|
||||
var yLParam = InteropMethods.GetYLParam(lParam.ToInt32());
|
||||
InteropMethods.GetWindowRect(Handle, out var rect);
|
||||
switch (_orientation)
|
||||
{
|
||||
case Dock.Left:
|
||||
if (yLParam - CornerGripThickness < rect.Top) return 13;
|
||||
if (yLParam + CornerGripThickness > rect.Bottom) return 16;
|
||||
return 10;
|
||||
case Dock.Top:
|
||||
if (xLParam - CornerGripThickness < rect.Left) return 13;
|
||||
if (xLParam + CornerGripThickness > rect.Right) return 14;
|
||||
return 12;
|
||||
case Dock.Right:
|
||||
if (yLParam - CornerGripThickness < rect.Top) return 14;
|
||||
if (yLParam + CornerGripThickness > rect.Bottom) return 17;
|
||||
return 11;
|
||||
default:
|
||||
if (xLParam - CornerGripThickness < rect.Left) return 16;
|
||||
if (xLParam + CornerGripThickness > rect.Right) return 17;
|
||||
return 15;
|
||||
}
|
||||
}
|
||||
|
||||
internal void CommitChanges()
|
||||
{
|
||||
InvalidateCachedBitmaps();
|
||||
UpdateWindowPosCore();
|
||||
UpdateLayeredWindowCore();
|
||||
_invalidatedValues = FieldInvalidationTypes.None;
|
||||
}
|
||||
|
||||
private void InvalidateCachedBitmaps()
|
||||
{
|
||||
if (_invalidatedValues.HasFlag(FieldInvalidationTypes.ActiveColor)) ClearCache(_activeGlowBitmaps);
|
||||
if (_invalidatedValues.HasFlag(FieldInvalidationTypes.InactiveColor)) ClearCache(_inactiveGlowBitmaps);
|
||||
}
|
||||
|
||||
private void UpdateWindowPosCore()
|
||||
{
|
||||
if (_invalidatedValues.HasFlag(FieldInvalidationTypes.Location) ||
|
||||
_invalidatedValues.HasFlag(FieldInvalidationTypes.Size) ||
|
||||
_invalidatedValues.HasFlag(FieldInvalidationTypes.Visibility))
|
||||
{
|
||||
var num = 532;
|
||||
if (_invalidatedValues.HasFlag(FieldInvalidationTypes.Visibility))
|
||||
{
|
||||
if (IsVisible)
|
||||
num |= 64;
|
||||
else
|
||||
num |= 131;
|
||||
}
|
||||
|
||||
if (!_invalidatedValues.HasFlag(FieldInvalidationTypes.Location)) num |= 2;
|
||||
if (!_invalidatedValues.HasFlag(FieldInvalidationTypes.Size)) num |= 1;
|
||||
InteropMethods.SetWindowPos(Handle, IntPtr.Zero, Left, Top, Width, Height, num);
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateLayeredWindowCore()
|
||||
{
|
||||
if (IsVisible && _invalidatedValues.HasFlag(FieldInvalidationTypes.Render))
|
||||
{
|
||||
if (IsPositionValid)
|
||||
{
|
||||
BeginDelayedRender();
|
||||
return;
|
||||
}
|
||||
|
||||
CancelDelayedRender();
|
||||
RenderLayeredWindow();
|
||||
}
|
||||
}
|
||||
|
||||
private void BeginDelayedRender()
|
||||
{
|
||||
if (!_pendingDelayRender)
|
||||
{
|
||||
_pendingDelayRender = true;
|
||||
CompositionTarget.Rendering += CommitDelayedRender;
|
||||
}
|
||||
}
|
||||
|
||||
private void CancelDelayedRender()
|
||||
{
|
||||
if (_pendingDelayRender)
|
||||
{
|
||||
_pendingDelayRender = false;
|
||||
CompositionTarget.Rendering -= CommitDelayedRender;
|
||||
}
|
||||
}
|
||||
|
||||
private void CommitDelayedRender(object sender, EventArgs e)
|
||||
{
|
||||
CancelDelayedRender();
|
||||
if (IsVisible) RenderLayeredWindow();
|
||||
}
|
||||
|
||||
private void RenderLayeredWindow()
|
||||
{
|
||||
using var glowDrawingContext = new GlowDrawingContext(Width, Height);
|
||||
if (glowDrawingContext.IsInitialized)
|
||||
{
|
||||
switch (_orientation)
|
||||
{
|
||||
case Dock.Left:
|
||||
DrawLeft(glowDrawingContext);
|
||||
break;
|
||||
case Dock.Top:
|
||||
DrawTop(glowDrawingContext);
|
||||
break;
|
||||
case Dock.Right:
|
||||
DrawRight(glowDrawingContext);
|
||||
break;
|
||||
default:
|
||||
DrawBottom(glowDrawingContext);
|
||||
break;
|
||||
}
|
||||
|
||||
var point = new InteropValues.POINT
|
||||
{
|
||||
X = Left,
|
||||
Y = Top
|
||||
};
|
||||
var size = new InteropValues.SIZE
|
||||
{
|
||||
cx = Width,
|
||||
cy = Height
|
||||
};
|
||||
var point2 = new InteropValues.POINT
|
||||
{
|
||||
X = 0,
|
||||
Y = 0
|
||||
};
|
||||
|
||||
InteropMethods.UpdateLayeredWindow(
|
||||
Handle,
|
||||
glowDrawingContext.ScreenDC,
|
||||
ref point,
|
||||
ref size,
|
||||
glowDrawingContext.WindowDC,
|
||||
ref point2,
|
||||
0u,
|
||||
ref glowDrawingContext.Blend,
|
||||
2u);
|
||||
}
|
||||
}
|
||||
|
||||
private GlowBitmap GetOrCreateBitmap(GlowDrawingContext drawingContext, GlowBitmapPart bitmapPart)
|
||||
{
|
||||
GlowBitmap[] array;
|
||||
Color color;
|
||||
if (IsActive)
|
||||
{
|
||||
array = _activeGlowBitmaps;
|
||||
color = ActiveGlowColor;
|
||||
}
|
||||
else
|
||||
{
|
||||
array = _inactiveGlowBitmaps;
|
||||
color = InactiveGlowColor;
|
||||
}
|
||||
|
||||
return array[(int) bitmapPart] ?? (array[(int) bitmapPart] = GlowBitmap.Create(drawingContext, bitmapPart, color));
|
||||
}
|
||||
|
||||
private void ClearCache(GlowBitmap[] cache)
|
||||
{
|
||||
for (var i = 0; i < cache.Length; i++)
|
||||
using (cache[i])
|
||||
{
|
||||
cache[i] = null;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void DisposeManagedResources()
|
||||
{
|
||||
ClearCache(_activeGlowBitmaps);
|
||||
ClearCache(_inactiveGlowBitmaps);
|
||||
}
|
||||
|
||||
protected override void DisposeNativeResources()
|
||||
{
|
||||
base.DisposeNativeResources();
|
||||
DisposedGlowEdges += 1L;
|
||||
}
|
||||
|
||||
private void DrawLeft(GlowDrawingContext drawingContext)
|
||||
{
|
||||
var orCreateBitmap = GetOrCreateBitmap(drawingContext, GlowBitmapPart.CornerTopLeft);
|
||||
var orCreateBitmap2 = GetOrCreateBitmap(drawingContext, GlowBitmapPart.LeftTop);
|
||||
var orCreateBitmap3 = GetOrCreateBitmap(drawingContext, GlowBitmapPart.Left);
|
||||
var orCreateBitmap4 = GetOrCreateBitmap(drawingContext, GlowBitmapPart.LeftBottom);
|
||||
var orCreateBitmap5 = GetOrCreateBitmap(drawingContext, GlowBitmapPart.CornerBottomLeft);
|
||||
var height = orCreateBitmap.Height;
|
||||
var num = height + orCreateBitmap2.Height;
|
||||
var num2 = drawingContext.Height - orCreateBitmap5.Height;
|
||||
var num3 = num2 - orCreateBitmap4.Height;
|
||||
var num4 = num3 - num;
|
||||
InteropMethods.SelectObject(drawingContext.BackgroundDC, orCreateBitmap.Handle);
|
||||
InteropMethods.AlphaBlend(drawingContext.WindowDC, 0, 0, orCreateBitmap.Width, orCreateBitmap.Height,
|
||||
drawingContext.BackgroundDC, 0, 0, orCreateBitmap.Width, orCreateBitmap.Height,
|
||||
drawingContext.Blend);
|
||||
InteropMethods.SelectObject(drawingContext.BackgroundDC, orCreateBitmap2.Handle);
|
||||
InteropMethods.AlphaBlend(drawingContext.WindowDC, 0, height, orCreateBitmap2.Width,
|
||||
orCreateBitmap2.Height, drawingContext.BackgroundDC, 0, 0, orCreateBitmap2.Width,
|
||||
orCreateBitmap2.Height, drawingContext.Blend);
|
||||
if (num4 > 0)
|
||||
{
|
||||
InteropMethods.SelectObject(drawingContext.BackgroundDC, orCreateBitmap3.Handle);
|
||||
InteropMethods.AlphaBlend(drawingContext.WindowDC, 0, num, orCreateBitmap3.Width, num4,
|
||||
drawingContext.BackgroundDC, 0, 0, orCreateBitmap3.Width, orCreateBitmap3.Height,
|
||||
drawingContext.Blend);
|
||||
}
|
||||
|
||||
InteropMethods.SelectObject(drawingContext.BackgroundDC, orCreateBitmap4.Handle);
|
||||
InteropMethods.AlphaBlend(drawingContext.WindowDC, 0, num3, orCreateBitmap4.Width,
|
||||
orCreateBitmap4.Height, drawingContext.BackgroundDC, 0, 0, orCreateBitmap4.Width,
|
||||
orCreateBitmap4.Height, drawingContext.Blend);
|
||||
InteropMethods.SelectObject(drawingContext.BackgroundDC, orCreateBitmap5.Handle);
|
||||
InteropMethods.AlphaBlend(drawingContext.WindowDC, 0, num2, orCreateBitmap5.Width,
|
||||
orCreateBitmap5.Height, drawingContext.BackgroundDC, 0, 0, orCreateBitmap5.Width,
|
||||
orCreateBitmap5.Height, drawingContext.Blend);
|
||||
}
|
||||
|
||||
private void DrawRight(GlowDrawingContext drawingContext)
|
||||
{
|
||||
var orCreateBitmap = GetOrCreateBitmap(drawingContext, GlowBitmapPart.CornerTopRight);
|
||||
var orCreateBitmap2 = GetOrCreateBitmap(drawingContext, GlowBitmapPart.RightTop);
|
||||
var orCreateBitmap3 = GetOrCreateBitmap(drawingContext, GlowBitmapPart.Right);
|
||||
var orCreateBitmap4 = GetOrCreateBitmap(drawingContext, GlowBitmapPart.RightBottom);
|
||||
var orCreateBitmap5 = GetOrCreateBitmap(drawingContext, GlowBitmapPart.CornerBottomRight);
|
||||
var height = orCreateBitmap.Height;
|
||||
var num = height + orCreateBitmap2.Height;
|
||||
var num2 = drawingContext.Height - orCreateBitmap5.Height;
|
||||
var num3 = num2 - orCreateBitmap4.Height;
|
||||
var num4 = num3 - num;
|
||||
InteropMethods.SelectObject(drawingContext.BackgroundDC, orCreateBitmap.Handle);
|
||||
InteropMethods.AlphaBlend(drawingContext.WindowDC, 0, 0, orCreateBitmap.Width, orCreateBitmap.Height,
|
||||
drawingContext.BackgroundDC, 0, 0, orCreateBitmap.Width, orCreateBitmap.Height,
|
||||
drawingContext.Blend);
|
||||
InteropMethods.SelectObject(drawingContext.BackgroundDC, orCreateBitmap2.Handle);
|
||||
InteropMethods.AlphaBlend(drawingContext.WindowDC, 0, height, orCreateBitmap2.Width,
|
||||
orCreateBitmap2.Height, drawingContext.BackgroundDC, 0, 0, orCreateBitmap2.Width,
|
||||
orCreateBitmap2.Height, drawingContext.Blend);
|
||||
if (num4 > 0)
|
||||
{
|
||||
InteropMethods.SelectObject(drawingContext.BackgroundDC, orCreateBitmap3.Handle);
|
||||
InteropMethods.AlphaBlend(drawingContext.WindowDC, 0, num, orCreateBitmap3.Width, num4,
|
||||
drawingContext.BackgroundDC, 0, 0, orCreateBitmap3.Width, orCreateBitmap3.Height,
|
||||
drawingContext.Blend);
|
||||
}
|
||||
|
||||
InteropMethods.SelectObject(drawingContext.BackgroundDC, orCreateBitmap4.Handle);
|
||||
InteropMethods.AlphaBlend(drawingContext.WindowDC, 0, num3, orCreateBitmap4.Width,
|
||||
orCreateBitmap4.Height, drawingContext.BackgroundDC, 0, 0, orCreateBitmap4.Width,
|
||||
orCreateBitmap4.Height, drawingContext.Blend);
|
||||
InteropMethods.SelectObject(drawingContext.BackgroundDC, orCreateBitmap5.Handle);
|
||||
InteropMethods.AlphaBlend(drawingContext.WindowDC, 0, num2, orCreateBitmap5.Width,
|
||||
orCreateBitmap5.Height, drawingContext.BackgroundDC, 0, 0, orCreateBitmap5.Width,
|
||||
orCreateBitmap5.Height, drawingContext.Blend);
|
||||
}
|
||||
|
||||
private void DrawTop(GlowDrawingContext drawingContext)
|
||||
{
|
||||
var orCreateBitmap = GetOrCreateBitmap(drawingContext, GlowBitmapPart.TopLeft);
|
||||
var orCreateBitmap2 = GetOrCreateBitmap(drawingContext, GlowBitmapPart.Top);
|
||||
var orCreateBitmap3 = GetOrCreateBitmap(drawingContext, GlowBitmapPart.TopRight);
|
||||
var num2 = GlowDepth + orCreateBitmap.Width;
|
||||
var num3 = drawingContext.Width - GlowDepth - orCreateBitmap3.Width;
|
||||
var num4 = num3 - num2;
|
||||
InteropMethods.SelectObject(drawingContext.BackgroundDC, orCreateBitmap.Handle);
|
||||
InteropMethods.AlphaBlend(drawingContext.WindowDC, GlowDepth, 0, orCreateBitmap.Width, orCreateBitmap.Height,
|
||||
drawingContext.BackgroundDC, 0, 0, orCreateBitmap.Width, orCreateBitmap.Height,
|
||||
drawingContext.Blend);
|
||||
if (num4 > 0)
|
||||
{
|
||||
InteropMethods.SelectObject(drawingContext.BackgroundDC, orCreateBitmap2.Handle);
|
||||
InteropMethods.AlphaBlend(drawingContext.WindowDC, num2, 0, num4, orCreateBitmap2.Height,
|
||||
drawingContext.BackgroundDC, 0, 0, orCreateBitmap2.Width, orCreateBitmap2.Height,
|
||||
drawingContext.Blend);
|
||||
}
|
||||
|
||||
InteropMethods.SelectObject(drawingContext.BackgroundDC, orCreateBitmap3.Handle);
|
||||
InteropMethods.AlphaBlend(drawingContext.WindowDC, num3, 0, orCreateBitmap3.Width,
|
||||
orCreateBitmap3.Height, drawingContext.BackgroundDC, 0, 0, orCreateBitmap3.Width,
|
||||
orCreateBitmap3.Height, drawingContext.Blend);
|
||||
}
|
||||
|
||||
private void DrawBottom(GlowDrawingContext drawingContext)
|
||||
{
|
||||
var orCreateBitmap = GetOrCreateBitmap(drawingContext, GlowBitmapPart.BottomLeft);
|
||||
var orCreateBitmap2 = GetOrCreateBitmap(drawingContext, GlowBitmapPart.Bottom);
|
||||
var orCreateBitmap3 = GetOrCreateBitmap(drawingContext, GlowBitmapPart.BottomRight);
|
||||
var num2 = GlowDepth + orCreateBitmap.Width;
|
||||
var num3 = drawingContext.Width - GlowDepth - orCreateBitmap3.Width;
|
||||
var num4 = num3 - num2;
|
||||
InteropMethods.SelectObject(drawingContext.BackgroundDC, orCreateBitmap.Handle);
|
||||
InteropMethods.AlphaBlend(drawingContext.WindowDC, GlowDepth, 0, orCreateBitmap.Width, orCreateBitmap.Height,
|
||||
drawingContext.BackgroundDC, 0, 0, orCreateBitmap.Width, orCreateBitmap.Height,
|
||||
drawingContext.Blend);
|
||||
if (num4 > 0)
|
||||
{
|
||||
InteropMethods.SelectObject(drawingContext.BackgroundDC, orCreateBitmap2.Handle);
|
||||
InteropMethods.AlphaBlend(drawingContext.WindowDC, num2, 0, num4, orCreateBitmap2.Height,
|
||||
drawingContext.BackgroundDC, 0, 0, orCreateBitmap2.Width, orCreateBitmap2.Height,
|
||||
drawingContext.Blend);
|
||||
}
|
||||
|
||||
InteropMethods.SelectObject(drawingContext.BackgroundDC, orCreateBitmap3.Handle);
|
||||
InteropMethods.AlphaBlend(drawingContext.WindowDC, num3, 0, orCreateBitmap3.Width,
|
||||
orCreateBitmap3.Height, drawingContext.BackgroundDC, 0, 0, orCreateBitmap3.Width,
|
||||
orCreateBitmap3.Height, drawingContext.Blend);
|
||||
}
|
||||
|
||||
internal void UpdateWindowPos()
|
||||
{
|
||||
var targetWindowHandle = TargetWindowHandle;
|
||||
InteropMethods.GetWindowRect(targetWindowHandle, out var rect);
|
||||
InteropMethods.GetWindowPlacement(targetWindowHandle);
|
||||
if (IsVisible)
|
||||
switch (_orientation)
|
||||
{
|
||||
case Dock.Left:
|
||||
Left = rect.Left - GlowDepth;
|
||||
Top = rect.Top - GlowDepth;
|
||||
Width = GlowDepth;
|
||||
Height = rect.Height + CornerGripThickness;
|
||||
return;
|
||||
case Dock.Top:
|
||||
Left = rect.Left - GlowDepth;
|
||||
Top = rect.Top - GlowDepth;
|
||||
Width = rect.Width + CornerGripThickness;
|
||||
Height = GlowDepth;
|
||||
return;
|
||||
case Dock.Right:
|
||||
Left = rect.Right;
|
||||
Top = rect.Top - GlowDepth;
|
||||
Width = GlowDepth;
|
||||
Height = rect.Height + CornerGripThickness;
|
||||
return;
|
||||
default:
|
||||
Left = rect.Left - GlowDepth;
|
||||
Top = rect.Bottom;
|
||||
Width = rect.Width + CornerGripThickness;
|
||||
Height = GlowDepth;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
[Flags]
|
||||
private enum FieldInvalidationTypes
|
||||
{
|
||||
None = 0,
|
||||
Location = 1,
|
||||
Size = 2,
|
||||
ActiveColor = 4,
|
||||
InactiveColor = 8,
|
||||
Render = 16,
|
||||
Visibility = 32
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using HandyControl.Tools.Interop;
|
||||
|
||||
namespace HandyControl.Data
|
||||
{
|
||||
public abstract class HwndWrapper : DisposableObject
|
||||
{
|
||||
private IntPtr _handle;
|
||||
|
||||
private bool _isHandleCreationAllowed = true;
|
||||
|
||||
private ushort _wndClassAtom;
|
||||
|
||||
private Delegate _wndProc;
|
||||
|
||||
protected ushort WindowClassAtom
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_wndClassAtom == 0) _wndClassAtom = CreateWindowClassCore();
|
||||
return _wndClassAtom;
|
||||
}
|
||||
}
|
||||
|
||||
public IntPtr Handle
|
||||
{
|
||||
get
|
||||
{
|
||||
EnsureHandle();
|
||||
return _handle;
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual bool IsWindowSubclassed => false;
|
||||
|
||||
protected virtual ushort CreateWindowClassCore() => RegisterClass(Guid.NewGuid().ToString());
|
||||
|
||||
protected virtual void DestroyWindowClassCore()
|
||||
{
|
||||
if (_wndClassAtom != 0)
|
||||
{
|
||||
var moduleHandle = InteropMethods.GetModuleHandle(null);
|
||||
InteropMethods.UnregisterClass(new IntPtr(_wndClassAtom), moduleHandle);
|
||||
_wndClassAtom = 0;
|
||||
}
|
||||
}
|
||||
|
||||
protected ushort RegisterClass(string className)
|
||||
{
|
||||
var wndClass = default(InteropValues.WNDCLASS);
|
||||
wndClass.cbClsExtra = 0;
|
||||
wndClass.cbWndExtra = 0;
|
||||
wndClass.hbrBackground = IntPtr.Zero;
|
||||
wndClass.hCursor = IntPtr.Zero;
|
||||
wndClass.hIcon = IntPtr.Zero;
|
||||
wndClass.lpfnWndProc = _wndProc = new InteropValues.WndProc(WndProc);
|
||||
wndClass.lpszClassName = className;
|
||||
wndClass.lpszMenuName = null;
|
||||
wndClass.style = 0u;
|
||||
return InteropMethods.RegisterClass(ref wndClass);
|
||||
}
|
||||
|
||||
private void SubclassWndProc()
|
||||
{
|
||||
_wndProc = new InteropValues.WndProc(WndProc);
|
||||
InteropMethods.SetWindowLong(_handle, -4, Marshal.GetFunctionPointerForDelegate(_wndProc));
|
||||
}
|
||||
|
||||
protected abstract IntPtr CreateWindowCore();
|
||||
|
||||
protected virtual void DestroyWindowCore()
|
||||
{
|
||||
if (_handle != IntPtr.Zero)
|
||||
{
|
||||
InteropMethods.DestroyWindow(_handle);
|
||||
_handle = IntPtr.Zero;
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam) =>
|
||||
InteropMethods.DefWindowProc(hwnd, msg, wParam, lParam);
|
||||
|
||||
public void EnsureHandle()
|
||||
{
|
||||
if (_handle == IntPtr.Zero)
|
||||
{
|
||||
if (!_isHandleCreationAllowed) return;
|
||||
_isHandleCreationAllowed = false;
|
||||
_handle = CreateWindowCore();
|
||||
if (IsWindowSubclassed) SubclassWndProc();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void DisposeNativeResources()
|
||||
{
|
||||
_isHandleCreationAllowed = false;
|
||||
DestroyWindowCore();
|
||||
DestroyWindowClassCore();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -302,6 +302,10 @@
|
||||
|
||||
internal const string WindowWin10 = nameof(WindowWin10);
|
||||
|
||||
internal const string WindowBlur = nameof(WindowBlur);
|
||||
|
||||
internal const string WindowGlow = nameof(WindowGlow);
|
||||
|
||||
internal const string AddTagButtonStyle = nameof(AddTagButtonStyle);
|
||||
|
||||
internal const string RadioGroupItemDefault = nameof(RadioGroupItemDefault);
|
||||
|
||||
@@ -42,6 +42,7 @@
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Slider\RangeSlider\TwoWayRangeBase.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Block\RunningBlock.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Window\GlowWindow.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Data\DisposableObject.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Data\Enum\DrawerShowMode.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Data\Enum\HatchStyle.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Data\Enum\HitMode.cs" />
|
||||
@@ -49,6 +50,12 @@
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Data\Enum\NotifyIconInfoType.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Data\Enum\StrokePosition.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Data\Enum\TransitionMode.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Data\GlowWindow\ChangeScope.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Data\GlowWindow\GlowBitmap.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Data\GlowWindow\GlowBitmapPart.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Data\GlowWindow\GlowDrawingContext.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Data\GlowWindow\GlowEdge.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Data\HwndWrapper.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Interactivity\Commands\CloseWindowCommand.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Interactivity\Commands\OpenLinkCommand.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Media\Animation\DiscreteGeometryKeyFrame.cs" />
|
||||
@@ -71,6 +78,7 @@
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Tools\Converter\Number2PercentageConverter.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Tools\Converter\RectangleCircularConverter.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Tools\Converter\ThicknessSplitConverter.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Tools\Extension\DependencyObjectExtension.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Tools\Extension\FrameworkElementExtension.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Tools\Extension\StringExtension.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Tools\Extension\ValueExtension.cs" />
|
||||
@@ -300,6 +308,7 @@
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Tools\Helper\ExternDllHelper.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Tools\Helper\IconHelper.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Tools\Helper\ResourceHelper.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Tools\Helper\ScreenHelper.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Tools\Helper\SecurityHelper.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Tools\Helper\SingleOpenHelper.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Tools\Helper\TokenizerHelper.cs" />
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace HandyControl.Tools.Extension
|
||||
{
|
||||
public static class DependencyObjectExtension
|
||||
{
|
||||
public static DependencyObject GetVisualOrLogicalParent(this DependencyObject sourceElement)
|
||||
{
|
||||
return sourceElement switch
|
||||
{
|
||||
null => null,
|
||||
Visual _ => (VisualTreeHelper.GetParent(sourceElement) ?? LogicalTreeHelper.GetParent(sourceElement)),
|
||||
_ => LogicalTreeHelper.GetParent(sourceElement)
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -52,6 +52,15 @@ namespace HandyControl.Tools
|
||||
SetLang(config.Lang);
|
||||
}
|
||||
|
||||
public void SetWindowDefaultStyle(object resourceKey = null)
|
||||
{
|
||||
var metadata = resourceKey == null
|
||||
? new FrameworkPropertyMetadata(Application.Current.FindResource(typeof(System.Windows.Window)))
|
||||
: new FrameworkPropertyMetadata(Application.Current.FindResource(resourceKey));
|
||||
|
||||
FrameworkElement.StyleProperty.OverrideMetadata(typeof(System.Windows.Window), metadata);
|
||||
}
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
#if netle40
|
||||
|
||||
@@ -1,14 +1,54 @@
|
||||
using System;
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
using HandyControl.Tools.Interop;
|
||||
|
||||
namespace HandyControl.Tools
|
||||
{
|
||||
internal class DpiHelper
|
||||
internal static class DpiHelper
|
||||
{
|
||||
[ThreadStatic]
|
||||
private const double LogicalDpi = 96.0;
|
||||
|
||||
[ThreadStatic]
|
||||
private static Matrix _transformToDip;
|
||||
|
||||
static DpiHelper()
|
||||
{
|
||||
var dC = InteropMethods.GetDC(IntPtr.Zero);
|
||||
if (dC != IntPtr.Zero)
|
||||
{
|
||||
DeviceDpiX = InteropMethods.GetDeviceCaps(dC, 88);
|
||||
DeviceDpiY = InteropMethods.GetDeviceCaps(dC, 90);
|
||||
InteropMethods.ReleaseDC(IntPtr.Zero, dC);
|
||||
}
|
||||
else
|
||||
{
|
||||
DeviceDpiX = LogicalDpi;
|
||||
DeviceDpiY = LogicalDpi;
|
||||
}
|
||||
|
||||
var identity = Matrix.Identity;
|
||||
var identity2 = Matrix.Identity;
|
||||
identity.Scale(DeviceDpiX / LogicalDpi, DeviceDpiY / LogicalDpi);
|
||||
identity2.Scale(LogicalDpi / DeviceDpiX, LogicalDpi / DeviceDpiY);
|
||||
TransformFromDevice = new MatrixTransform(identity2);
|
||||
TransformFromDevice.Freeze();
|
||||
TransformToDevice = new MatrixTransform(identity);
|
||||
TransformToDevice.Freeze();
|
||||
}
|
||||
|
||||
public static MatrixTransform TransformFromDevice { get; }
|
||||
|
||||
public static MatrixTransform TransformToDevice { get; }
|
||||
|
||||
public static double DeviceDpiX { get; }
|
||||
|
||||
public static double DeviceDpiY { get; }
|
||||
|
||||
public static double LogicalToDeviceUnitsScalingFactorX => TransformToDevice.Matrix.M11;
|
||||
|
||||
public static double LogicalToDeviceUnitsScalingFactorY => TransformToDevice.Matrix.M22;
|
||||
|
||||
public static Point DevicePixelsToLogical(Point devicePoint, double dpiScaleX, double dpiScaleY)
|
||||
{
|
||||
_transformToDip = Matrix.Identity;
|
||||
@@ -18,9 +58,22 @@ namespace HandyControl.Tools
|
||||
|
||||
public static Size DeviceSizeToLogical(Size deviceSize, double dpiScaleX, double dpiScaleY)
|
||||
{
|
||||
Point pt = DevicePixelsToLogical(new Point(deviceSize.Width, deviceSize.Height), dpiScaleX, dpiScaleY);
|
||||
|
||||
var pt = DevicePixelsToLogical(new Point(deviceSize.Width, deviceSize.Height), dpiScaleX, dpiScaleY);
|
||||
return new Size(pt.X, pt.Y);
|
||||
}
|
||||
|
||||
public static Rect LogicalToDeviceUnits(this Rect logicalRect)
|
||||
{
|
||||
var result = logicalRect;
|
||||
result.Transform(TransformToDevice.Matrix);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Rect DeviceToLogicalUnits(this Rect deviceRect)
|
||||
{
|
||||
var result = deviceRect;
|
||||
result.Transform(TransformFromDevice.Matrix);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -81,7 +81,7 @@ namespace HandyControl.Tools
|
||||
{
|
||||
var bi = new InteropValues.BITMAPINFO(width, -height, 32)
|
||||
{
|
||||
bmiHeader_biCompression = InteropValues.BI_RGB
|
||||
biCompression = InteropValues.BI_RGB
|
||||
};
|
||||
|
||||
var bits = IntPtr.Zero;
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Windows;
|
||||
using HandyControl.Tools.Interop;
|
||||
|
||||
namespace HandyControl.Tools
|
||||
{
|
||||
internal class ScreenHelper
|
||||
{
|
||||
internal static void FindMaximumSingleMonitorRectangle(Rect windowRect, out Rect screenSubRect, out Rect monitorRect)
|
||||
{
|
||||
var windowRect2 = new InteropValues.RECT(windowRect);
|
||||
FindMaximumSingleMonitorRectangle(windowRect2, out var rect, out var rect2);
|
||||
screenSubRect = new Rect(rect.Position, rect.Size);
|
||||
monitorRect = new Rect(rect2.Position, rect2.Size);
|
||||
}
|
||||
|
||||
private static void FindMaximumSingleMonitorRectangle(InteropValues.RECT windowRect, out InteropValues.RECT screenSubRect, out InteropValues.RECT monitorRect)
|
||||
{
|
||||
var rects = new List<InteropValues.RECT>();
|
||||
InteropMethods.EnumDisplayMonitors(IntPtr.Zero, IntPtr.Zero,
|
||||
delegate(IntPtr hMonitor, IntPtr hdcMonitor, ref InteropValues.RECT rect, IntPtr lpData)
|
||||
{
|
||||
var monitorInfo = default(InteropValues.MONITORINFO);
|
||||
monitorInfo.cbSize = (uint) Marshal.SizeOf(typeof(InteropValues.MONITORINFO));
|
||||
InteropMethods.GetMonitorInfo(hMonitor, ref monitorInfo);
|
||||
rects.Add(monitorInfo.rcWork);
|
||||
return true;
|
||||
}, IntPtr.Zero);
|
||||
|
||||
var num = 0L;
|
||||
|
||||
screenSubRect = new InteropValues.RECT
|
||||
{
|
||||
Left = 0,
|
||||
Right = 0,
|
||||
Top = 0,
|
||||
Bottom = 0
|
||||
};
|
||||
|
||||
monitorRect = new InteropValues.RECT
|
||||
{
|
||||
Left = 0,
|
||||
Right = 0,
|
||||
Top = 0,
|
||||
Bottom = 0
|
||||
};
|
||||
|
||||
foreach (var current in rects)
|
||||
{
|
||||
var rect = current;
|
||||
InteropMethods.IntersectRect(out var rECT2, ref rect, ref windowRect);
|
||||
var num2 = (long) (rECT2.Width * rECT2.Height);
|
||||
if (num2 > num)
|
||||
{
|
||||
screenSubRect = rECT2;
|
||||
monitorRect = current;
|
||||
num = num2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal static void FindMonitorRectsFromPoint(Point point, out Rect monitorRect, out Rect workAreaRect)
|
||||
{
|
||||
var intPtr = InteropMethods.MonitorFromPoint(new InteropValues.POINT
|
||||
{
|
||||
X = (int) point.X,
|
||||
Y = (int) point.Y
|
||||
}, 2);
|
||||
|
||||
monitorRect = new Rect(0.0, 0.0, 0.0, 0.0);
|
||||
workAreaRect = new Rect(0.0, 0.0, 0.0, 0.0);
|
||||
|
||||
if (intPtr != IntPtr.Zero)
|
||||
{
|
||||
InteropValues.MONITORINFO monitorInfo = default;
|
||||
monitorInfo.cbSize = (uint) Marshal.SizeOf(typeof(InteropValues.MONITORINFO));
|
||||
InteropMethods.GetMonitorInfo(intPtr, ref monitorInfo);
|
||||
monitorRect = new Rect(monitorInfo.rcMonitor.Position, monitorInfo.rcMonitor.Size);
|
||||
workAreaRect = new Rect(monitorInfo.rcWork.Position, monitorInfo.rcWork.Size);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Interop;
|
||||
using System.Windows.Media;
|
||||
using HandyControl.Tools.Interop;
|
||||
|
||||
namespace HandyControl.Tools
|
||||
{
|
||||
@@ -11,10 +12,7 @@ namespace HandyControl.Tools
|
||||
internal static VisualStateGroup TryGetVisualStateGroup(DependencyObject d, string groupName)
|
||||
{
|
||||
var root = GetImplementationRoot(d);
|
||||
if (root == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if (root == null) return null;
|
||||
|
||||
return VisualStateManager
|
||||
.GetVisualStateGroups(root)?
|
||||
@@ -31,10 +29,7 @@ namespace HandyControl.Tools
|
||||
|
||||
public static T GetChild<T>(DependencyObject d) where T : DependencyObject
|
||||
{
|
||||
if (d is T t)
|
||||
{
|
||||
return t;
|
||||
}
|
||||
if (d is T t) return t;
|
||||
|
||||
for (var i = 0; i < VisualTreeHelper.GetChildrenCount(d); i++)
|
||||
{
|
||||
@@ -47,7 +42,34 @@ namespace HandyControl.Tools
|
||||
return default;
|
||||
}
|
||||
|
||||
public static IntPtr GetHandle(this Visual visual) =>
|
||||
(PresentationSource.FromVisual(visual) as HwndSource)?.Handle ?? IntPtr.Zero;
|
||||
public static IntPtr GetHandle(this Visual visual)
|
||||
{
|
||||
return (PresentationSource.FromVisual(visual) as HwndSource)?.Handle ?? IntPtr.Zero;
|
||||
}
|
||||
|
||||
internal static void HitTestVisibleElements(Visual visual, HitTestResultCallback resultCallback,
|
||||
HitTestParameters parameters)
|
||||
{
|
||||
VisualTreeHelper.HitTest(visual, ExcludeNonVisualElements, resultCallback, parameters);
|
||||
}
|
||||
|
||||
private static HitTestFilterBehavior ExcludeNonVisualElements(DependencyObject potentialHitTestTarget)
|
||||
{
|
||||
if (!(potentialHitTestTarget is Visual)) return HitTestFilterBehavior.ContinueSkipSelfAndChildren;
|
||||
|
||||
if (!(potentialHitTestTarget is UIElement uIElement) || uIElement.IsVisible && uIElement.IsEnabled)
|
||||
return HitTestFilterBehavior.Continue;
|
||||
|
||||
return HitTestFilterBehavior.ContinueSkipSelfAndChildren;
|
||||
}
|
||||
|
||||
internal static bool ModifyStyle(IntPtr hWnd, int styleToRemove, int styleToAdd)
|
||||
{
|
||||
var windowLong = InteropMethods.GetWindowLong(hWnd, InteropValues.GWL.STYLE);
|
||||
var num = (windowLong & ~styleToRemove) | styleToAdd;
|
||||
if (num == windowLong) return false;
|
||||
InteropMethods.SetWindowLong(hWnd, InteropValues.GWL.STYLE, num);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,83 +10,87 @@ namespace HandyControl.Tools.Interop
|
||||
{
|
||||
internal class InteropMethods
|
||||
{
|
||||
private static int vsmNotifyOwnerActivate;
|
||||
|
||||
public static readonly IntPtr HRGN_NONE = new IntPtr(-1);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.User32, CharSet = CharSet.Auto)]
|
||||
[ResourceExposure(ResourceScope.None)]
|
||||
public static extern int RegisterWindowMessage(string msg);
|
||||
internal static extern int RegisterWindowMessage(string msg);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.User32, SetLastError = true, CharSet = CharSet.Auto)]
|
||||
public static extern int MapWindowPoints(IntPtr hWndFrom, IntPtr hWndTo, ref InteropValues.RECT lpPoints, uint cPoints);
|
||||
internal static extern int MapWindowPoints(IntPtr hWndFrom, IntPtr hWndTo, ref InteropValues.RECT lpPoints, uint cPoints);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.Kernel32, SetLastError = true, CharSet = CharSet.Auto)]
|
||||
public static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, out InteropValues.TBBUTTON lpBuffer,
|
||||
internal static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, out InteropValues.TBBUTTON lpBuffer,
|
||||
int dwSize, out int lpNumberOfBytesRead);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.Kernel32, SetLastError = true)]
|
||||
public static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, out InteropValues.RECT lpBuffer,
|
||||
internal static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, out InteropValues.RECT lpBuffer,
|
||||
int dwSize, out int lpNumberOfBytesRead);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.Kernel32, SetLastError = true)]
|
||||
public static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, out InteropValues.TRAYDATA lpBuffer,
|
||||
internal static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, out InteropValues.TRAYDATA lpBuffer,
|
||||
int dwSize, out int lpNumberOfBytesRead);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.User32, CharSet = CharSet.Auto)]
|
||||
public static extern uint SendMessage(IntPtr hWnd, uint Msg, uint wParam, IntPtr lParam);
|
||||
internal static extern uint SendMessage(IntPtr hWnd, uint Msg, uint wParam, IntPtr lParam);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.User32, SetLastError = true, CharSet = CharSet.Auto)]
|
||||
public static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId);
|
||||
internal static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.Kernel32, SetLastError = true, CharSet = CharSet.Auto)]
|
||||
public static extern IntPtr OpenProcess(InteropValues.ProcessAccess dwDesiredAccess,
|
||||
internal static extern IntPtr OpenProcess(InteropValues.ProcessAccess dwDesiredAccess,
|
||||
[MarshalAs(UnmanagedType.Bool)] bool bInheritHandle, uint dwProcessId);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.Kernel32, SetLastError = true, CharSet = CharSet.Auto)]
|
||||
public static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, int dwSize,
|
||||
internal static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, int dwSize,
|
||||
InteropValues.AllocationType flAllocationType, InteropValues.MemoryProtection flProtect);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.Kernel32, SetLastError = true, CharSet = CharSet.Auto)]
|
||||
public static extern int CloseHandle(IntPtr hObject);
|
||||
internal static extern int CloseHandle(IntPtr hObject);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.Kernel32, SetLastError = true, CharSet = CharSet.Auto)]
|
||||
public static extern bool VirtualFreeEx(IntPtr hProcess, IntPtr lpAddress, int dwSize, InteropValues.FreeType dwFreeType);
|
||||
internal static extern bool VirtualFreeEx(IntPtr hProcess, IntPtr lpAddress, int dwSize, InteropValues.FreeType dwFreeType);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.User32, SetLastError = true)]
|
||||
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
|
||||
internal static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.User32, SetLastError = true)]
|
||||
public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass,
|
||||
internal static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass,
|
||||
string lpszWindow);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.User32)]
|
||||
public static extern int GetWindowRect(IntPtr hwnd, out InteropValues.RECT lpRect);
|
||||
internal static extern int GetWindowRect(IntPtr hwnd, out InteropValues.RECT lpRect);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.User32, CharSet = CharSet.Auto)]
|
||||
public static extern bool GetCursorPos(out InteropValues.POINT pt);
|
||||
internal static extern bool GetCursorPos(out InteropValues.POINT pt);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.User32)]
|
||||
public static extern IntPtr GetDesktopWindow();
|
||||
internal static extern IntPtr GetDesktopWindow();
|
||||
|
||||
[DllImport(InteropValues.ExternDll.User32, SetLastError = true)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
public static extern bool AddClipboardFormatListener(IntPtr hwnd);
|
||||
internal static extern bool AddClipboardFormatListener(IntPtr hwnd);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.User32, SetLastError = true)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
public static extern bool RemoveClipboardFormatListener(IntPtr hwnd);
|
||||
internal static extern bool RemoveClipboardFormatListener(IntPtr hwnd);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.User32)]
|
||||
public static extern IntPtr GetSystemMenu(IntPtr hWnd, bool bRevert);
|
||||
internal static extern IntPtr GetSystemMenu(IntPtr hWnd, bool bRevert);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.User32)]
|
||||
public static extern bool InsertMenu(IntPtr hMenu, int wPosition, int wFlags, int wIDNewItem, string lpNewItem);
|
||||
internal static extern bool InsertMenu(IntPtr hMenu, int wPosition, int wFlags, int wIDNewItem, string lpNewItem);
|
||||
|
||||
[SecurityCritical]
|
||||
[SuppressUnmanagedCodeSecurity]
|
||||
[DllImport(InteropValues.ExternDll.User32, SetLastError = true, ExactSpelling = true, EntryPoint = nameof(GetDC),
|
||||
CharSet = CharSet.Auto)]
|
||||
public static extern IntPtr IntGetDC(HandleRef hWnd);
|
||||
internal static extern IntPtr IntGetDC(HandleRef hWnd);
|
||||
|
||||
[SecurityCritical]
|
||||
public static IntPtr GetDC(HandleRef hWnd)
|
||||
internal static IntPtr GetDC(HandleRef hWnd)
|
||||
{
|
||||
var hDc = IntGetDC(hWnd);
|
||||
if (hDc == IntPtr.Zero) throw new Win32Exception();
|
||||
@@ -97,10 +101,10 @@ namespace HandyControl.Tools.Interop
|
||||
[SecurityCritical]
|
||||
[SuppressUnmanagedCodeSecurity]
|
||||
[DllImport(InteropValues.ExternDll.User32, ExactSpelling = true, EntryPoint = nameof(ReleaseDC), CharSet = CharSet.Auto)]
|
||||
public static extern int IntReleaseDC(HandleRef hWnd, HandleRef hDC);
|
||||
internal static extern int IntReleaseDC(HandleRef hWnd, HandleRef hDC);
|
||||
|
||||
[SecurityCritical]
|
||||
public static int ReleaseDC(HandleRef hWnd, HandleRef hDC)
|
||||
internal static int ReleaseDC(HandleRef hWnd, HandleRef hDC)
|
||||
{
|
||||
HandleCollector.Remove((IntPtr) hDC, CommonHandles.HDC);
|
||||
return IntReleaseDC(hWnd, hDC);
|
||||
@@ -109,12 +113,12 @@ namespace HandyControl.Tools.Interop
|
||||
[SecurityCritical]
|
||||
[SuppressUnmanagedCodeSecurity]
|
||||
[DllImport(InteropValues.ExternDll.Gdi32, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Auto)]
|
||||
public static extern int GetDeviceCaps(HandleRef hDC, int nIndex);
|
||||
internal static extern int GetDeviceCaps(HandleRef hDC, int nIndex);
|
||||
|
||||
[SecurityCritical]
|
||||
[SuppressUnmanagedCodeSecurity]
|
||||
[DllImport(InteropValues.ExternDll.User32)]
|
||||
public static extern int GetSystemMetrics(InteropValues.SM nIndex);
|
||||
internal static extern int GetSystemMetrics(InteropValues.SM nIndex);
|
||||
|
||||
[SecurityCritical]
|
||||
[SuppressUnmanagedCodeSecurity]
|
||||
@@ -122,7 +126,7 @@ namespace HandyControl.Tools.Interop
|
||||
private static extern bool IntDestroyIcon(IntPtr hIcon);
|
||||
|
||||
[SecurityCritical]
|
||||
public static bool DestroyIcon(IntPtr hIcon)
|
||||
internal static bool DestroyIcon(IntPtr hIcon)
|
||||
{
|
||||
var result = IntDestroyIcon(hIcon);
|
||||
return result;
|
||||
@@ -134,14 +138,14 @@ namespace HandyControl.Tools.Interop
|
||||
private static extern bool IntDeleteObject(IntPtr hObject);
|
||||
|
||||
[SecurityCritical]
|
||||
public static bool DeleteObject(IntPtr hObject)
|
||||
internal static bool DeleteObject(IntPtr hObject)
|
||||
{
|
||||
var result = IntDeleteObject(hObject);
|
||||
return result;
|
||||
}
|
||||
|
||||
[SecurityCritical]
|
||||
public static BitmapHandle CreateDIBSection(HandleRef hdc, ref InteropValues.BITMAPINFO bitmapInfo, int iUsage,
|
||||
internal static BitmapHandle CreateDIBSection(HandleRef hdc, ref InteropValues.BITMAPINFO bitmapInfo, int iUsage,
|
||||
ref IntPtr ppvBits, SafeFileMappingHandle hSection, int dwOffset)
|
||||
{
|
||||
if (hSection == null) hSection = new SafeFileMappingHandle(IntPtr.Zero);
|
||||
@@ -151,7 +155,7 @@ namespace HandyControl.Tools.Interop
|
||||
}
|
||||
|
||||
[DllImport(InteropValues.ExternDll.Kernel32, EntryPoint = "CloseHandle", CharSet = CharSet.Auto, SetLastError = true)]
|
||||
public static extern bool IntCloseHandle(HandleRef handle);
|
||||
internal static extern bool IntCloseHandle(HandleRef handle);
|
||||
|
||||
[SecurityCritical]
|
||||
[SuppressUnmanagedCodeSecurity]
|
||||
@@ -168,7 +172,7 @@ namespace HandyControl.Tools.Interop
|
||||
InteropValues.ICONINFO iconInfo);
|
||||
|
||||
[SecurityCritical]
|
||||
public static IconHandle CreateIconIndirect([In] [MarshalAs(UnmanagedType.LPStruct)]
|
||||
internal static IconHandle CreateIconIndirect([In] [MarshalAs(UnmanagedType.LPStruct)]
|
||||
InteropValues.ICONINFO iconInfo)
|
||||
{
|
||||
var hIcon = PrivateCreateIconIndirect(iconInfo);
|
||||
@@ -221,12 +225,12 @@ namespace HandyControl.Tools.Interop
|
||||
out IconHandle phiconSmall, int nIcons);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.Shell32, CharSet = CharSet.Auto)]
|
||||
public static extern int Shell_NotifyIcon(int message, InteropValues.NOTIFYICONDATA pnid);
|
||||
internal static extern int Shell_NotifyIcon(int message, InteropValues.NOTIFYICONDATA pnid);
|
||||
|
||||
[SecurityCritical]
|
||||
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
||||
[DllImport(InteropValues.ExternDll.User32, SetLastError = true, CharSet = CharSet.Unicode, EntryPoint = "CreateWindowExW")]
|
||||
public static extern IntPtr CreateWindowEx(
|
||||
internal static extern IntPtr CreateWindowEx(
|
||||
int dwExStyle,
|
||||
[MarshalAs(UnmanagedType.LPWStr)] string lpClassName,
|
||||
[MarshalAs(UnmanagedType.LPWStr)] string lpWindowName,
|
||||
@@ -243,39 +247,273 @@ namespace HandyControl.Tools.Interop
|
||||
[SecurityCritical]
|
||||
[SuppressUnmanagedCodeSecurity]
|
||||
[DllImport(InteropValues.ExternDll.User32, CharSet = CharSet.Unicode, SetLastError = true, BestFitMapping = false)]
|
||||
public static extern short RegisterClass(InteropValues.WNDCLASS wc);
|
||||
internal static extern short RegisterClass(InteropValues.WNDCLASS wc);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.User32, CharSet = CharSet.Auto)]
|
||||
public static extern IntPtr DefWindowProc(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);
|
||||
internal static extern IntPtr DefWindowProc(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.User32, ExactSpelling = true, CharSet = CharSet.Auto)]
|
||||
public static extern bool SetForegroundWindow(IntPtr hWnd);
|
||||
internal static extern bool SetForegroundWindow(IntPtr hWnd);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.User32, CharSet = CharSet.Auto, SetLastError = true)]
|
||||
public static extern IntPtr CallNextHookEx(IntPtr hhk, int nCode, IntPtr wParam, IntPtr lParam);
|
||||
internal static extern IntPtr CallNextHookEx(IntPtr hhk, int nCode, IntPtr wParam, IntPtr lParam);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.Kernel32, CharSet = CharSet.Auto, SetLastError = true)]
|
||||
public static extern IntPtr GetModuleHandle(string lpModuleName);
|
||||
internal static extern IntPtr GetModuleHandle(string lpModuleName);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.User32, CharSet = CharSet.Auto, SetLastError = true)]
|
||||
public static extern bool UnhookWindowsHookEx(IntPtr hhk);
|
||||
internal static extern bool UnhookWindowsHookEx(IntPtr hhk);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.User32, CharSet = CharSet.Auto, SetLastError = true)]
|
||||
public static extern IntPtr SetWindowsHookEx(int idHook, InteropValues.HookProc lpfn, IntPtr hMod, uint dwThreadId);
|
||||
internal static extern IntPtr SetWindowsHookEx(int idHook, InteropValues.HookProc lpfn, IntPtr hMod, uint dwThreadId);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.User32, SetLastError = true)]
|
||||
public static extern IntPtr GetWindowDC(IntPtr window);
|
||||
internal static extern IntPtr GetWindowDC(IntPtr window);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.Gdi32, SetLastError = true)]
|
||||
public static extern uint GetPixel(IntPtr dc, int x, int y);
|
||||
internal static extern uint GetPixel(IntPtr dc, int x, int y);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.User32, SetLastError = true)]
|
||||
public static extern int ReleaseDC(IntPtr window, IntPtr dc);
|
||||
internal static extern int ReleaseDC(IntPtr window, IntPtr dc);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.Gdi32, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Auto)]
|
||||
public static extern int GetDeviceCaps(IntPtr hdc, int nIndex);
|
||||
internal static extern int GetDeviceCaps(IntPtr hdc, int nIndex);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.User32, CharSet = CharSet.Auto)]
|
||||
public static extern IntPtr GetDC(IntPtr ptr);
|
||||
internal static extern IntPtr GetDC(IntPtr ptr);
|
||||
|
||||
internal static int NOTIFYOWNERACTIVATE
|
||||
{
|
||||
get
|
||||
{
|
||||
if (vsmNotifyOwnerActivate == 0)
|
||||
{
|
||||
vsmNotifyOwnerActivate = RegisterWindowMessage("NOTIFYOWNERACTIVATE{A982313C-756C-4da9-8BD0-0C375A45784B}");
|
||||
}
|
||||
return vsmNotifyOwnerActivate;
|
||||
}
|
||||
}
|
||||
|
||||
[DllImport(InteropValues.ExternDll.User32, SetLastError = true)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
private static extern bool GetWindowPlacement(IntPtr hwnd, InteropValues.WINDOWPLACEMENT lpwndpl);
|
||||
|
||||
internal static InteropValues.WINDOWPLACEMENT GetWindowPlacement(IntPtr hwnd)
|
||||
{
|
||||
InteropValues.WINDOWPLACEMENT wINDOWPLACEMENT = new InteropValues.WINDOWPLACEMENT();
|
||||
if (GetWindowPlacement(hwnd, wINDOWPLACEMENT))
|
||||
{
|
||||
return wINDOWPLACEMENT;
|
||||
}
|
||||
throw new Win32Exception(Marshal.GetLastWin32Error());
|
||||
}
|
||||
|
||||
[DllImport(InteropValues.ExternDll.User32)]
|
||||
internal static extern int GetSystemMetrics(int index);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.User32)]
|
||||
internal static extern int TrackPopupMenuEx(IntPtr hmenu, uint fuFlags, int x, int y, IntPtr hwnd, IntPtr lptpm);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.User32)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
internal static extern bool EnableMenuItem(IntPtr menu, uint uIDEnableItem, uint uEnable);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.User32)]
|
||||
internal static extern short GetKeyState(int vKey);
|
||||
|
||||
internal static bool IsKeyPressed(int vKey) => GetKeyState(vKey) < 0;
|
||||
|
||||
internal static IntPtr MakeParam(int lowWord, int highWord) => new IntPtr((lowWord & 65535) | highWord << 16);
|
||||
|
||||
internal static int GetXLParam(int lParam) => LoWord(lParam);
|
||||
|
||||
internal static int GetYLParam(int lParam) => HiWord(lParam);
|
||||
|
||||
internal static int HiWord(int value) => (short)(value >> 16);
|
||||
|
||||
internal static int LoWord(int value) => (short)(value & 65535);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.User32)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
internal static extern bool ScreenToClient(IntPtr hWnd, ref InteropValues.POINT point);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.User32)]
|
||||
internal static extern IntPtr MonitorFromWindow(IntPtr handle, int flags);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.User32)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
internal static extern bool ClientToScreen(IntPtr hWnd, ref InteropValues.POINT point);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.User32)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
internal static extern bool EnumThreadWindows(uint dwThreadId, InteropValues.EnumWindowsProc lpfn, IntPtr lParam);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.User32, SetLastError = true)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
internal static extern bool PostMessage(IntPtr hWnd, int nMsg, IntPtr wParam, IntPtr lParam);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.User32)]
|
||||
internal static extern IntPtr GetDCEx(IntPtr hWnd, IntPtr hrgnClip, int dwFlags);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.Gdi32)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
internal static extern bool DeleteDC(IntPtr hdc);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.Gdi32, SetLastError = true)]
|
||||
internal static extern IntPtr CreateCompatibleDC(IntPtr hdc);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.Gdi32, ExactSpelling = true, SetLastError = true)]
|
||||
internal static extern IntPtr SelectObject(IntPtr hdc, IntPtr hgdiobj);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.Gdi32, CallingConvention = CallingConvention.StdCall, ExactSpelling = true)]
|
||||
internal static extern IntPtr CreateRoundRectRgn(int nLeftRect, int nTopRect, int nRightRect, int nBottomRect, int nWidthEllipse, int nHeightEllipse);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.Gdi32, CallingConvention = CallingConvention.StdCall, ExactSpelling = true)]
|
||||
internal static extern IntPtr CreateRectRgn(int nLeftRect, int nTopRect, int nRightRect, int nBottomRect);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.Gdi32, CallingConvention = CallingConvention.StdCall, ExactSpelling = true)]
|
||||
internal static extern IntPtr CreateRectRgnIndirect(ref InteropValues.RECT lprc);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.Gdi32, CallingConvention = CallingConvention.StdCall, ExactSpelling = true)]
|
||||
private static extern int CombineRgn(IntPtr hrngDest, IntPtr hrgnSrc1, IntPtr hrgnSrc2, int fnCombineMode);
|
||||
|
||||
internal static int CombineRgn(IntPtr hrnDest, IntPtr hrgnSrc1, IntPtr hrgnSrc2,
|
||||
InteropValues.CombineMode combineMode) => CombineRgn(hrnDest, hrgnSrc1, hrgnSrc2, (int) combineMode);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.User32, CallingConvention = CallingConvention.StdCall, ExactSpelling = true)]
|
||||
internal static extern int SetWindowRgn(IntPtr hWnd, IntPtr hRgn, [MarshalAs(UnmanagedType.Bool)] bool redraw);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.User32, CharSet = CharSet.Unicode, SetLastError = true)]
|
||||
internal static extern IntPtr SendMessage(IntPtr hWnd, int nMsg, IntPtr wParam, IntPtr lParam);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.User32)]
|
||||
internal static extern IntPtr MonitorFromPoint(InteropValues.POINT pt, int flags);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.User32)]
|
||||
internal static extern IntPtr GetWindow(IntPtr hwnd, int nCmd);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.User32)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
internal static extern bool GetWindowInfo(IntPtr hwnd, ref InteropValues.WINDOWINFO pwi);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.User32)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
internal static extern bool IsWindowVisible(IntPtr hwnd);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.User32)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
internal static extern bool IsIconic(IntPtr hwnd);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.User32)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
internal static extern bool IsZoomed(IntPtr hwnd);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.User32, CharSet = CharSet.Auto, ExactSpelling = true)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
internal static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int x, int y, int cx, int cy, int flags);
|
||||
|
||||
internal static System.Windows.Point GetCursorPos()
|
||||
{
|
||||
var result = default(System.Windows.Point);
|
||||
if (GetCursorPos(out var point))
|
||||
{
|
||||
result.X = point.X;
|
||||
result.Y = point.Y;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
[DllImport(InteropValues.ExternDll.User32)]
|
||||
private static extern int GetWindowLong(IntPtr hWnd, int nIndex);
|
||||
|
||||
internal static int GetWindowLong(IntPtr hWnd, InteropValues.GWL nIndex) => GetWindowLong(hWnd, (int)nIndex);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.User32)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
internal static extern bool GetClientRect(IntPtr hwnd, out InteropValues.RECT lpRect);
|
||||
|
||||
internal static IntPtr SetWindowLong(IntPtr hWnd, int nIndex, IntPtr dwNewLong)
|
||||
{
|
||||
if (IntPtr.Size == 4)
|
||||
{
|
||||
return SetWindowLongPtr32(hWnd, nIndex, dwNewLong);
|
||||
}
|
||||
return SetWindowLongPtr64(hWnd, nIndex, dwNewLong);
|
||||
}
|
||||
|
||||
[DllImport(InteropValues.ExternDll.User32, CharSet = CharSet.Auto, EntryPoint = "SetWindowLong")]
|
||||
internal static extern IntPtr SetWindowLongPtr32(IntPtr hWnd, int nIndex, IntPtr dwNewLong);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.User32, CharSet = CharSet.Auto, EntryPoint = "SetWindowLongPtr")]
|
||||
internal static extern IntPtr SetWindowLongPtr64(IntPtr hWnd, int nIndex, IntPtr dwNewLong);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.User32, CharSet = CharSet.Unicode)]
|
||||
private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.User32, CharSet = CharSet.Unicode)]
|
||||
private static extern IntPtr SetWindowLongPtr(IntPtr hWnd, int nIndex, IntPtr dwNewLong);
|
||||
|
||||
internal static IntPtr SetWindowLongPtr(IntPtr hWnd, InteropValues.GWLP nIndex, IntPtr dwNewLong)
|
||||
{
|
||||
if (IntPtr.Size == 8)
|
||||
{
|
||||
return SetWindowLongPtr(hWnd, (int)nIndex, dwNewLong);
|
||||
}
|
||||
return new IntPtr(SetWindowLong(hWnd, (int)nIndex, dwNewLong.ToInt32()));
|
||||
}
|
||||
|
||||
internal static int SetWindowLong(IntPtr hWnd, InteropValues.GWL nIndex, int dwNewLong) => SetWindowLong(hWnd, (int)nIndex, dwNewLong);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.User32, CharSet = CharSet.Unicode)]
|
||||
internal static extern ushort RegisterClass(ref InteropValues.WNDCLASS lpWndClass);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.Kernel32)]
|
||||
internal static extern uint GetCurrentThreadId();
|
||||
|
||||
[DllImport(InteropValues.ExternDll.User32, CharSet = CharSet.Unicode, SetLastError = true)]
|
||||
internal static extern IntPtr CreateWindowEx(int dwExStyle, IntPtr classAtom, string lpWindowName, int dwStyle, int x, int y, int nWidth, int nHeight, IntPtr hWndParent, IntPtr hMenu, IntPtr hInstance, IntPtr lpParam);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.Gdi32)]
|
||||
internal static extern IntPtr CreateSolidBrush(int colorref);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.User32)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
internal static extern bool DestroyWindow(IntPtr hwnd);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.User32)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
internal static extern bool UnregisterClass(IntPtr classAtom, IntPtr hInstance);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.User32)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
internal static extern bool UpdateLayeredWindow(IntPtr hwnd, IntPtr hdcDest, ref InteropValues.POINT pptDest, ref InteropValues.SIZE psize, IntPtr hdcSrc, ref InteropValues.POINT pptSrc, uint crKey, [In] ref InteropValues.BLENDFUNCTION pblend, uint dwFlags);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.User32)]
|
||||
internal static extern bool RedrawWindow(IntPtr hWnd, IntPtr lprcUpdate, IntPtr hrgnUpdate, InteropValues.RedrawWindowFlags flags);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.User32)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
internal static extern bool FillRect(IntPtr hDC, ref InteropValues.RECT rect, IntPtr hbrush);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.User32)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
internal static extern bool EnumDisplayMonitors(IntPtr hdc, IntPtr lprcClip, InteropValues.EnumMonitorsDelegate lpfnEnum, IntPtr dwData);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.User32)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
internal static extern bool IntersectRect(out InteropValues.RECT lprcDst, [In] ref InteropValues.RECT lprcSrc1, [In] ref InteropValues.RECT lprcSrc2);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.User32)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
internal static extern bool GetMonitorInfo(IntPtr hMonitor, ref InteropValues.MONITORINFO monitorInfo);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.Gdi32, SetLastError = true)]
|
||||
internal static extern IntPtr CreateDIBSection(IntPtr hdc, ref InteropValues.BITMAPINFO pbmi, uint iUsage, out IntPtr ppvBits, IntPtr hSection, uint dwOffset);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.MsImg)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
internal static extern bool AlphaBlend(IntPtr hdcDest, int xoriginDest, int yoriginDest, int wDest, int hDest, IntPtr hdcSrc, int xoriginSrc, int yoriginSrc, int wSrc, int hSrc, InteropValues.BLENDFUNCTION pfn);
|
||||
|
||||
internal static int GET_SC_WPARAM(IntPtr wParam) => (int)wParam & 65520;
|
||||
}
|
||||
}
|
||||
@@ -1,18 +1,36 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
using System.Windows;
|
||||
|
||||
namespace HandyControl.Tools.Interop
|
||||
{
|
||||
public class InteropValues
|
||||
internal class InteropValues
|
||||
{
|
||||
#region public
|
||||
internal static class ExternDll
|
||||
{
|
||||
public const string
|
||||
User32 = "user32.dll",
|
||||
Gdi32 = "gdi32.dll",
|
||||
Kernel32 = "kernel32.dll",
|
||||
Shell32 = "shell32.dll",
|
||||
MsImg = "msimg32.dll";
|
||||
}
|
||||
|
||||
public delegate IntPtr HookProc(int code, IntPtr wParam, IntPtr lParam);
|
||||
internal delegate IntPtr HookProc(int code, IntPtr wParam, IntPtr lParam);
|
||||
|
||||
public delegate IntPtr WndProc(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);
|
||||
internal delegate IntPtr WndProc(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);
|
||||
|
||||
public const int
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
internal delegate bool EnumMonitorsDelegate(IntPtr hMonitor, IntPtr hdcMonitor, ref RECT lprcMonitor, IntPtr dwData);
|
||||
|
||||
internal delegate bool EnumWindowsProc(IntPtr hWnd, IntPtr lParam);
|
||||
|
||||
internal delegate IntPtr SubclassProc(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam, UIntPtr id, IntPtr refData);
|
||||
|
||||
internal delegate IntPtr WindowsHookProc(CbtHookAction code, IntPtr wParam, IntPtr lParam);
|
||||
|
||||
internal const int
|
||||
WS_CHILD = 0x40000000,
|
||||
BITSPIXEL = 12,
|
||||
PLANES = 14,
|
||||
@@ -73,7 +91,7 @@ namespace HandyControl.Tools.Interop
|
||||
SW_HIDE = 0;
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
|
||||
public class NOTIFYICONDATA
|
||||
internal class NOTIFYICONDATA
|
||||
{
|
||||
public int cbSize = Marshal.SizeOf(typeof(NOTIFYICONDATA));
|
||||
public IntPtr hWnd;
|
||||
@@ -93,40 +111,8 @@ namespace HandyControl.Tools.Interop
|
||||
public int dwInfoFlags;
|
||||
}
|
||||
|
||||
[Flags]
|
||||
public enum ProcessAccess
|
||||
{
|
||||
AllAccess = CreateThread | DuplicateHandle | QueryInformation | SetInformation | Terminate | VMOperation | VMRead | VMWrite | Synchronize,
|
||||
CreateThread = 0x2,
|
||||
DuplicateHandle = 0x40,
|
||||
QueryInformation = 0x400,
|
||||
SetInformation = 0x200,
|
||||
Terminate = 0x1,
|
||||
VMOperation = 0x8,
|
||||
VMRead = 0x10,
|
||||
VMWrite = 0x20,
|
||||
Synchronize = 0x100000
|
||||
}
|
||||
|
||||
[Serializable, StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
|
||||
public struct RECT
|
||||
{
|
||||
public int Left;
|
||||
public int Top;
|
||||
public int Right;
|
||||
public int Bottom;
|
||||
|
||||
public RECT(int left, int top, int right, int bottom)
|
||||
{
|
||||
Left = left;
|
||||
Top = top;
|
||||
Right = right;
|
||||
Bottom = bottom;
|
||||
}
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||
public struct TBBUTTON
|
||||
internal struct TBBUTTON
|
||||
{
|
||||
public int iBitmap;
|
||||
public int idCommand;
|
||||
@@ -136,7 +122,7 @@ namespace HandyControl.Tools.Interop
|
||||
}
|
||||
|
||||
[Flags]
|
||||
public enum AllocationType
|
||||
internal enum AllocationType
|
||||
{
|
||||
Commit = 0x1000,
|
||||
Reserve = 0x2000,
|
||||
@@ -150,7 +136,7 @@ namespace HandyControl.Tools.Interop
|
||||
}
|
||||
|
||||
[Flags]
|
||||
public enum MemoryProtection
|
||||
internal enum MemoryProtection
|
||||
{
|
||||
Execute = 0x10,
|
||||
ExecuteRead = 0x20,
|
||||
@@ -166,7 +152,7 @@ namespace HandyControl.Tools.Interop
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct TRAYDATA
|
||||
internal struct TRAYDATA
|
||||
{
|
||||
public IntPtr hwnd;
|
||||
public uint uID;
|
||||
@@ -177,14 +163,14 @@ namespace HandyControl.Tools.Interop
|
||||
}
|
||||
|
||||
[Flags]
|
||||
public enum FreeType
|
||||
internal enum FreeType
|
||||
{
|
||||
Decommit = 0x4000,
|
||||
Release = 0x8000,
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct POINT
|
||||
internal struct POINT
|
||||
{
|
||||
public int X;
|
||||
public int Y;
|
||||
@@ -196,14 +182,14 @@ namespace HandyControl.Tools.Interop
|
||||
}
|
||||
}
|
||||
|
||||
public enum HookType
|
||||
internal enum HookType
|
||||
{
|
||||
WH_KEYBOARD_LL = 13,
|
||||
WH_MOUSE_LL = 14
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct MOUSEHOOKSTRUCT
|
||||
internal struct MOUSEHOOKSTRUCT
|
||||
{
|
||||
public POINT pt;
|
||||
public IntPtr hwnd;
|
||||
@@ -211,17 +197,227 @@ namespace HandyControl.Tools.Interop
|
||||
public IntPtr dwExtraInfo;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region internal
|
||||
|
||||
internal static class ExternDll
|
||||
[Flags]
|
||||
internal enum ProcessAccess
|
||||
{
|
||||
public const string
|
||||
User32 = "user32.dll",
|
||||
Gdi32 = "gdi32.dll",
|
||||
Kernel32 = "kernel32.dll",
|
||||
Shell32 = "shell32.dll";
|
||||
AllAccess = CreateThread | DuplicateHandle | QueryInformation | SetInformation | Terminate | VMOperation | VMRead | VMWrite | Synchronize,
|
||||
CreateThread = 0x2,
|
||||
DuplicateHandle = 0x40,
|
||||
QueryInformation = 0x400,
|
||||
SetInformation = 0x200,
|
||||
Terminate = 0x1,
|
||||
VMOperation = 0x8,
|
||||
VMRead = 0x10,
|
||||
VMWrite = 0x20,
|
||||
Synchronize = 0x100000
|
||||
}
|
||||
|
||||
[Serializable, StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
|
||||
internal struct RECT
|
||||
{
|
||||
public int Left;
|
||||
public int Top;
|
||||
public int Right;
|
||||
public int Bottom;
|
||||
|
||||
public RECT(int left, int top, int right, int bottom)
|
||||
{
|
||||
Left = left;
|
||||
Top = top;
|
||||
Right = right;
|
||||
Bottom = bottom;
|
||||
}
|
||||
|
||||
public RECT(Rect rect)
|
||||
{
|
||||
Left = (int)rect.Left;
|
||||
Top = (int)rect.Top;
|
||||
Right = (int)rect.Right;
|
||||
Bottom = (int)rect.Bottom;
|
||||
}
|
||||
|
||||
public Point Position => new Point(Left, Top);
|
||||
public Size Size => new Size(Width, Height);
|
||||
|
||||
public int Height
|
||||
{
|
||||
get => Bottom - Top;
|
||||
set => Bottom = Top + value;
|
||||
}
|
||||
|
||||
public int Width
|
||||
{
|
||||
get => Right - Left;
|
||||
set => Right = Left + value;
|
||||
}
|
||||
|
||||
public void Offset(int dx, int dy)
|
||||
{
|
||||
Left += dx;
|
||||
Right += dx;
|
||||
Top += dy;
|
||||
Bottom += dy;
|
||||
}
|
||||
|
||||
public Int32Rect ToInt32Rect() => new Int32Rect(Left, Top, Width, Height);
|
||||
}
|
||||
|
||||
internal struct BLENDFUNCTION
|
||||
{
|
||||
public byte BlendOp;
|
||||
public byte BlendFlags;
|
||||
public byte SourceConstantAlpha;
|
||||
public byte AlphaFormat;
|
||||
}
|
||||
internal enum GWL
|
||||
{
|
||||
STYLE = -16,
|
||||
EXSTYLE = -20
|
||||
}
|
||||
internal enum GWLP
|
||||
{
|
||||
WNDPROC = -4,
|
||||
HINSTANCE = -6,
|
||||
HWNDPARENT = -8,
|
||||
USERDATA = -21,
|
||||
ID = -12
|
||||
}
|
||||
internal enum CombineMode
|
||||
{
|
||||
RGN_AND = 1,
|
||||
RGN_OR,
|
||||
RGN_XOR,
|
||||
RGN_DIFF,
|
||||
RGN_COPY,
|
||||
RGN_MIN = 1,
|
||||
RGN_MAX = 5
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal class BITMAPFILEHEADER
|
||||
{
|
||||
public ushort bfType;
|
||||
public uint bfSize;
|
||||
public ushort bfReserved1;
|
||||
public ushort bfReserved2;
|
||||
public uint bfOffBits;
|
||||
}
|
||||
|
||||
internal struct BITMAPINFOHEADER
|
||||
{
|
||||
internal uint biSize;
|
||||
internal int biWidth;
|
||||
internal int biHeight;
|
||||
internal ushort biPlanes;
|
||||
internal ushort biBitCount;
|
||||
internal uint biCompression;
|
||||
internal uint biSizeImage;
|
||||
internal int biXPelsPerMeter;
|
||||
internal int biYPelsPerMeter;
|
||||
internal uint biClrUsed;
|
||||
internal uint biClrImportant;
|
||||
}
|
||||
|
||||
internal struct PictDescBitmap
|
||||
{
|
||||
internal int cbSizeOfStruct;
|
||||
internal int pictureType;
|
||||
internal IntPtr hBitmap;
|
||||
internal IntPtr hPalette;
|
||||
internal int unused;
|
||||
internal static PictDescBitmap Default =>
|
||||
new PictDescBitmap
|
||||
{
|
||||
cbSizeOfStruct = 20,
|
||||
pictureType = 1,
|
||||
hBitmap = IntPtr.Zero,
|
||||
hPalette = IntPtr.Zero
|
||||
};
|
||||
}
|
||||
|
||||
[Flags]
|
||||
internal enum RedrawWindowFlags : uint
|
||||
{
|
||||
Invalidate = 1u,
|
||||
InternalPaint = 2u,
|
||||
Erase = 4u,
|
||||
Validate = 8u,
|
||||
NoInternalPaint = 16u,
|
||||
NoErase = 32u,
|
||||
NoChildren = 64u,
|
||||
AllChildren = 128u,
|
||||
UpdateNow = 256u,
|
||||
EraseNow = 512u,
|
||||
Frame = 1024u,
|
||||
NoFrame = 2048u
|
||||
}
|
||||
|
||||
internal enum CbtHookAction
|
||||
{
|
||||
HCBT_MOVESIZE,
|
||||
HCBT_MINMAX,
|
||||
HCBT_QS,
|
||||
HCBT_CREATEWND,
|
||||
HCBT_DESTROYWND,
|
||||
HCBT_ACTIVATE,
|
||||
HCBT_CLICKSKIPPED,
|
||||
HCBT_KEYSKIPPED,
|
||||
HCBT_SYSCOMMAND,
|
||||
HCBT_SETFOCUS
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal class WINDOWPOS
|
||||
{
|
||||
public IntPtr hwnd;
|
||||
public IntPtr hwndInsertAfter;
|
||||
public int x;
|
||||
public int y;
|
||||
public int cx;
|
||||
public int cy;
|
||||
public uint flags;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal class WINDOWPLACEMENT
|
||||
{
|
||||
public int length = Marshal.SizeOf(typeof(WINDOWPLACEMENT));
|
||||
public int flags;
|
||||
public int showCmd;
|
||||
public POINT ptMinPosition;
|
||||
public POINT ptMaxPosition;
|
||||
public RECT rcNormalPosition;
|
||||
}
|
||||
|
||||
internal struct WINDOWINFO
|
||||
{
|
||||
public int cbSize;
|
||||
public RECT rcWindow;
|
||||
public RECT rcClient;
|
||||
public int dwStyle;
|
||||
public int dwExStyle;
|
||||
public uint dwWindowStatus;
|
||||
public uint cxWindowBorders;
|
||||
public uint cyWindowBorders;
|
||||
public ushort atomWindowType;
|
||||
public ushort wCreatorVersion;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 4)]
|
||||
internal struct SIZE
|
||||
{
|
||||
[ComAliasName("Microsoft.VisualStudio.OLE.Interop.LONG")]
|
||||
public int cx;
|
||||
[ComAliasName("Microsoft.VisualStudio.OLE.Interop.LONG")]
|
||||
public int cy;
|
||||
}
|
||||
|
||||
internal struct MONITORINFO
|
||||
{
|
||||
public uint cbSize;
|
||||
public RECT rcMonitor;
|
||||
public RECT rcWork;
|
||||
public uint dwFlags;
|
||||
}
|
||||
|
||||
internal enum SM
|
||||
@@ -455,59 +651,61 @@ namespace HandyControl.Tools.Interop
|
||||
internal const int FALSE = 0;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
|
||||
internal class WNDCLASS
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
|
||||
internal struct WNDCLASS
|
||||
{
|
||||
public int style;
|
||||
public WndProc lpfnWndProc;
|
||||
public uint style;
|
||||
public Delegate lpfnWndProc;
|
||||
public int cbClsExtra;
|
||||
public int cbWndExtra;
|
||||
public IntPtr hInstance;
|
||||
public IntPtr hIcon;
|
||||
public IntPtr hCursor;
|
||||
public IntPtr hbrBackground;
|
||||
[MarshalAs(UnmanagedType.LPWStr)]
|
||||
public string lpszMenuName;
|
||||
[MarshalAs(UnmanagedType.LPWStr)]
|
||||
public string lpszClassName;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 2)]
|
||||
internal struct BITMAPINFO
|
||||
{
|
||||
public int bmiHeader_biSize;
|
||||
public int biSize;
|
||||
|
||||
public int bmiHeader_biWidth;
|
||||
public int biWidth;
|
||||
|
||||
public int bmiHeader_biHeight;
|
||||
public int biHeight;
|
||||
|
||||
public short bmiHeader_biPlanes;
|
||||
public short biPlanes;
|
||||
|
||||
public short bmiHeader_biBitCount;
|
||||
public short biBitCount;
|
||||
|
||||
public int bmiHeader_biCompression;
|
||||
public int biCompression;
|
||||
|
||||
public int bmiHeader_biSizeImage;
|
||||
public int biSizeImage;
|
||||
|
||||
public int bmiHeader_biXPelsPerMeter;
|
||||
public int biXPelsPerMeter;
|
||||
|
||||
public int bmiHeader_biYPelsPerMeter;
|
||||
public int biYPelsPerMeter;
|
||||
|
||||
public int bmiHeader_biClrUsed;
|
||||
public int biClrUsed;
|
||||
|
||||
public int bmiHeader_biClrImportant;
|
||||
public int biClrImportant;
|
||||
|
||||
public BITMAPINFO(int width, int height, short bpp)
|
||||
{
|
||||
bmiHeader_biSize = SizeOf();
|
||||
bmiHeader_biWidth = width;
|
||||
bmiHeader_biHeight = height;
|
||||
bmiHeader_biPlanes = 1;
|
||||
bmiHeader_biBitCount = bpp;
|
||||
bmiHeader_biCompression = 0;
|
||||
bmiHeader_biSizeImage = 0;
|
||||
bmiHeader_biXPelsPerMeter = 0;
|
||||
bmiHeader_biYPelsPerMeter = 0;
|
||||
bmiHeader_biClrUsed = 0;
|
||||
bmiHeader_biClrImportant = 0;
|
||||
biSize = SizeOf();
|
||||
biWidth = width;
|
||||
biHeight = height;
|
||||
biPlanes = 1;
|
||||
biBitCount = bpp;
|
||||
biCompression = 0;
|
||||
biSizeImage = 0;
|
||||
biXPelsPerMeter = 0;
|
||||
biYPelsPerMeter = 0;
|
||||
biClrUsed = 0;
|
||||
biClrImportant = 0;
|
||||
}
|
||||
|
||||
[SecuritySafeCritical]
|
||||
@@ -526,7 +724,5 @@ namespace HandyControl.Tools.Interop
|
||||
public BitmapHandle hbmMask = null;
|
||||
public BitmapHandle hbmColor = null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user