add Screenshot
This commit is contained in:
1 parent
08ae754ea3
commit
46b1297aa7
28 files changed
+923
-100
No files matched your search
@@ -7,7 +7,6 @@ using System.Runtime;
|
||||
using System.Security.Authentication;
|
||||
using System.Threading;
|
||||
using System.Windows;
|
||||
using System.Windows.Media.Animation;
|
||||
using HandyControl.Data;
|
||||
using HandyControl.Tools;
|
||||
using HandyControlDemo.Data;
|
||||
|
||||
@@ -36,12 +36,12 @@
|
||||
<UniformGrid Grid.Column="1" Columns="3">
|
||||
<Button Margin="8,0" Tag="0" Style="{StaticResource Button4PoptipStyle}">
|
||||
<hc:Poptip.Instance>
|
||||
<hc:Poptip Content="{x:Static langs:Lang.Text}" Placement="TopLeft"/>
|
||||
<hc:Poptip Content="{x:Static langs:Lang.Text}" PlacementType="TopLeft"/>
|
||||
</hc:Poptip.Instance>
|
||||
</Button>
|
||||
<Button Margin="8,0" Tag="1" Style="{StaticResource Button4PoptipStyle}">
|
||||
<hc:Poptip.Instance>
|
||||
<hc:Poptip Placement="Top">
|
||||
<hc:Poptip PlacementType="Top">
|
||||
<hc:Poptip.Content>
|
||||
<Path Width="100" Height="100" Fill="#f06632" Data="{StaticResource LogoGeometry}"/>
|
||||
</hc:Poptip.Content>
|
||||
@@ -54,7 +54,7 @@
|
||||
<ToggleButton hc:Poptip.HitMode="None" hc:Poptip.IsOpen="{Binding IsChecked,RelativeSource={RelativeSource Self}}" hc:Poptip.Content="{x:Static langs:Lang.Text}" hc:Poptip.Placement="RightTop" Margin="8,16" Tag="3" Style="{StaticResource ToggleButton4PoptipStyle}"/>
|
||||
<ToggleButton Margin="8,16" Tag="4" Style="{StaticResource ToggleButton4PoptipStyle}">
|
||||
<hc:Poptip.Instance>
|
||||
<hc:Poptip Background="Transparent" Padding="0" BorderThickness="0" HitMode="None" Placement="Right" IsOpen="{Binding Target.IsChecked,RelativeSource={RelativeSource Self}}">
|
||||
<hc:Poptip Background="Transparent" Padding="0" BorderThickness="0" HitMode="None" PlacementType="Right" IsOpen="{Binding Target.IsChecked,RelativeSource={RelativeSource Self}}">
|
||||
<hc:Poptip.Content>
|
||||
<Path Width="100" Height="100" Fill="#f06632" Data="{StaticResource LogoGeometry}"/>
|
||||
</hc:Poptip.Content>
|
||||
|
||||
@@ -13,11 +13,11 @@ namespace HandyControl.Controls
|
||||
public static Visibility GetVisibility(DependencyObject element) => (Visibility) element.GetValue(VisibilityProperty);
|
||||
|
||||
public static readonly DependencyProperty PlacementProperty = DependencyProperty.RegisterAttached(
|
||||
"Placement", typeof(TipPlacement), typeof(TipElement), new PropertyMetadata(default(TipPlacement)));
|
||||
"Placement", typeof(PlacementType), typeof(TipElement), new PropertyMetadata(default(PlacementType)));
|
||||
|
||||
public static void SetPlacement(DependencyObject element, TipPlacement value) => element.SetValue(PlacementProperty, value);
|
||||
public static void SetPlacement(DependencyObject element, PlacementType value) => element.SetValue(PlacementProperty, value);
|
||||
|
||||
public static TipPlacement GetPlacement(DependencyObject element) => (TipPlacement) element.GetValue(PlacementProperty);
|
||||
public static PlacementType GetPlacement(DependencyObject element) => (PlacementType) element.GetValue(PlacementProperty);
|
||||
|
||||
public static readonly DependencyProperty StringFormatProperty = DependencyProperty.RegisterAttached(
|
||||
"StringFormat", typeof(string), typeof(TipElement), new PropertyMetadata("#0.0"));
|
||||
|
||||
@@ -60,7 +60,7 @@ namespace HandyControl.Controls
|
||||
if (!_colorPicker.IsMouseOver && window.IsMouseOver)
|
||||
{
|
||||
UpdateCursor(true);
|
||||
if (e.Message == MouseHookMessageType.LeftButtonDown)
|
||||
if (e.MessageType == MouseHookMessageType.LeftButtonDown)
|
||||
{
|
||||
var brush = new SolidColorBrush(GetColorAt(e.Point.X, e.Point.Y));
|
||||
_colorPicker.SelectedBrush = brush;
|
||||
|
||||
@@ -106,19 +106,19 @@ namespace HandyControl.Controls
|
||||
set => SetValue(OffsetProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty PlacementProperty = DependencyProperty.RegisterAttached(
|
||||
"Placement", typeof(TipPlacement), typeof(Poptip), new PropertyMetadata(TipPlacement.Top));
|
||||
public static readonly DependencyProperty PlacementTypeProperty = DependencyProperty.RegisterAttached(
|
||||
"PlacementType", typeof(PlacementType), typeof(Poptip), new PropertyMetadata(PlacementType.Top));
|
||||
|
||||
public static void SetPlacement(DependencyObject element, TipPlacement value)
|
||||
=> element.SetValue(PlacementProperty, value);
|
||||
public static void SetPlacement(DependencyObject element, PlacementType value)
|
||||
=> element.SetValue(PlacementTypeProperty, value);
|
||||
|
||||
public static TipPlacement GetPlacement(DependencyObject element)
|
||||
=> (TipPlacement) element.GetValue(PlacementProperty);
|
||||
public static PlacementType GetPlacement(DependencyObject element)
|
||||
=> (PlacementType) element.GetValue(PlacementTypeProperty);
|
||||
|
||||
public TipPlacement Placement
|
||||
public PlacementType PlacementType
|
||||
{
|
||||
get => (TipPlacement)GetValue(PlacementProperty);
|
||||
set => SetValue(PlacementProperty, value);
|
||||
get => (PlacementType)GetValue(PlacementTypeProperty);
|
||||
set => SetValue(PlacementTypeProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty IsOpenProperty = DependencyProperty.RegisterAttached(
|
||||
@@ -192,65 +192,65 @@ namespace HandyControl.Controls
|
||||
var offsetY = .0;
|
||||
|
||||
var poptip = (Poptip)GetInstance(Target);
|
||||
var popupPlacement = poptip.Placement;
|
||||
var popupPlacement = poptip.PlacementType;
|
||||
var popupOffset = poptip.Offset;
|
||||
|
||||
PlacementMode placementMode;
|
||||
|
||||
switch (popupPlacement)
|
||||
{
|
||||
case TipPlacement.LeftTop:
|
||||
case PlacementType.LeftTop:
|
||||
offsetX = -popupOffset;
|
||||
placementMode = PlacementMode.Left;
|
||||
break;
|
||||
case TipPlacement.Left:
|
||||
case PlacementType.Left:
|
||||
offsetX = -popupOffset;
|
||||
offsetY = (targetHeight - height) / 2;
|
||||
placementMode = PlacementMode.Left;
|
||||
break;
|
||||
case TipPlacement.LeftBottom:
|
||||
case PlacementType.LeftBottom:
|
||||
offsetX = -popupOffset;
|
||||
offsetY = targetHeight - height;
|
||||
placementMode = PlacementMode.Left;
|
||||
break;
|
||||
case TipPlacement.TopLeft:
|
||||
case PlacementType.TopLeft:
|
||||
offsetY = -popupOffset;
|
||||
placementMode = PlacementMode.Top;
|
||||
break;
|
||||
case TipPlacement.Top:
|
||||
case PlacementType.Top:
|
||||
offsetX = (targetWidth - width) / 2;
|
||||
offsetY = -popupOffset;
|
||||
placementMode = PlacementMode.Top;
|
||||
break;
|
||||
case TipPlacement.TopRight:
|
||||
case PlacementType.TopRight:
|
||||
offsetX = targetWidth - width;
|
||||
offsetY = -popupOffset;
|
||||
placementMode = PlacementMode.Top;
|
||||
break;
|
||||
case TipPlacement.RightTop:
|
||||
case PlacementType.RightTop:
|
||||
offsetX = popupOffset;
|
||||
placementMode = PlacementMode.Right;
|
||||
break;
|
||||
case TipPlacement.Right:
|
||||
case PlacementType.Right:
|
||||
offsetX = popupOffset;
|
||||
offsetY = (targetHeight - height) / 2;
|
||||
placementMode = PlacementMode.Right;
|
||||
break;
|
||||
case TipPlacement.RightBottom:
|
||||
case PlacementType.RightBottom:
|
||||
offsetX = popupOffset;
|
||||
offsetY = targetHeight - height;
|
||||
placementMode = PlacementMode.Right;
|
||||
break;
|
||||
case TipPlacement.BottomLeft:
|
||||
case PlacementType.BottomLeft:
|
||||
offsetY = popupOffset;
|
||||
placementMode = PlacementMode.Bottom;
|
||||
break;
|
||||
case TipPlacement.Bottom:
|
||||
case PlacementType.Bottom:
|
||||
offsetX = (targetWidth - width) / 2;
|
||||
offsetY = popupOffset;
|
||||
placementMode = PlacementMode.Bottom;
|
||||
break;
|
||||
case TipPlacement.BottomRight:
|
||||
case PlacementType.BottomRight:
|
||||
offsetX = targetWidth - width;
|
||||
offsetY = popupOffset;
|
||||
placementMode = PlacementMode.Bottom;
|
||||
@@ -271,7 +271,7 @@ namespace HandyControl.Controls
|
||||
if (!GetIsInstance(Target))
|
||||
{
|
||||
SetCurrentValue(ContentProperty, GetContent(Target));
|
||||
SetCurrentValue(PlacementProperty, GetPlacement(Target));
|
||||
SetCurrentValue(PlacementTypeProperty, GetPlacement(Target));
|
||||
SetCurrentValue(HitModeProperty, GetHitMode(Target));
|
||||
SetCurrentValue(OffsetProperty, GetOffset(Target));
|
||||
SetCurrentValue(IsOpenProperty, GetIsOpen(Target));
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace HandyControl.Controls
|
||||
{
|
||||
public class Screenshot
|
||||
{
|
||||
public event EventHandler Snapped;
|
||||
|
||||
public ImageSource Source { get; set; }
|
||||
|
||||
public void Start() => new ScreenshotWindow(this).Show();
|
||||
|
||||
internal void OnSnapped() => Snapped?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,572 @@
|
||||
using System;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Interop;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using HandyControl.Data;
|
||||
using HandyControl.Tools;
|
||||
using HandyControl.Tools.Interop;
|
||||
|
||||
namespace HandyControl.Controls
|
||||
{
|
||||
[TemplatePart(Name = ElementCanvas, Type = typeof(InkCanvas))]
|
||||
[TemplatePart(Name = ElementMaskAreaLeft, Type = typeof(FrameworkElement))]
|
||||
[TemplatePart(Name = ElementMaskAreaTop, Type = typeof(FrameworkElement))]
|
||||
[TemplatePart(Name = ElementMaskAreaRight, Type = typeof(FrameworkElement))]
|
||||
[TemplatePart(Name = ElementMaskAreaBottom, Type = typeof(FrameworkElement))]
|
||||
[TemplatePart(Name = ElementTargetArea, Type = typeof(InkCanvas))]
|
||||
[TemplatePart(Name = ElementTextSize, Type = typeof(TextBlock))]
|
||||
public class ScreenshotWindow : System.Windows.Window
|
||||
{
|
||||
#region fields
|
||||
|
||||
private readonly Screenshot _screenshot;
|
||||
|
||||
#region const
|
||||
|
||||
private const int RectMinLength = 14;
|
||||
|
||||
private const int IntervalLength = 1;
|
||||
|
||||
private const int IntervalBigLength = 10;
|
||||
|
||||
private const int SnapLength = 4;
|
||||
|
||||
#endregion
|
||||
|
||||
#region IntPtr
|
||||
|
||||
private IntPtr _desktopWindowHandle;
|
||||
|
||||
private IntPtr _mouseOverWindowHandle;
|
||||
|
||||
private readonly IntPtr _screenshotWindowHandle;
|
||||
|
||||
#endregion
|
||||
|
||||
#region status
|
||||
|
||||
private InteropValues.RECT _desktopWindowRect;
|
||||
|
||||
private InteropValues.RECT _targetWindowRect;
|
||||
|
||||
private readonly int[] _flagArr = new int[4];
|
||||
|
||||
private bool _canDrag;
|
||||
|
||||
private bool _receiveMoveMsg = true;
|
||||
|
||||
private Point _mousePointOld;
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region Elements
|
||||
|
||||
internal InkCanvas Canvas { get; set; }
|
||||
|
||||
internal FrameworkElement MaskAreaLeft { get; set; }
|
||||
|
||||
internal FrameworkElement MaskAreaTop { get; set; }
|
||||
|
||||
internal FrameworkElement MaskAreaRight { get; set; }
|
||||
|
||||
internal FrameworkElement MaskAreaBottom { get; set; }
|
||||
|
||||
internal FrameworkElement TargetArea { get; set; }
|
||||
|
||||
internal TextBlock TextSize { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region const
|
||||
|
||||
private const string ElementCanvas = "PART_Canvas";
|
||||
|
||||
private const string ElementMaskAreaLeft = "PART_MaskAreaLeft";
|
||||
|
||||
private const string ElementMaskAreaTop = "PART_MaskAreaTop";
|
||||
|
||||
private const string ElementMaskAreaRight = "PART_MaskAreaRight";
|
||||
|
||||
private const string ElementMaskAreaBottom = "PART_MaskAreaBottom";
|
||||
|
||||
private const string ElementTargetArea = "PART_TargetArea";
|
||||
|
||||
private const string ElementTextSize = "PART_TextSize";
|
||||
|
||||
#endregion
|
||||
|
||||
#region prop
|
||||
|
||||
public static readonly DependencyProperty IsDrawingProperty = DependencyProperty.Register(
|
||||
"IsDrawing", typeof(bool), typeof(ScreenshotWindow), new PropertyMetadata(ValueBoxes.FalseBox));
|
||||
|
||||
public bool IsDrawing
|
||||
{
|
||||
get => (bool)GetValue(IsDrawingProperty);
|
||||
internal set => SetValue(IsDrawingProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty IsSelectingProperty = DependencyProperty.Register(
|
||||
"IsSelecting", typeof(bool), typeof(ScreenshotWindow), new PropertyMetadata(ValueBoxes.FalseBox));
|
||||
|
||||
public bool IsSelecting
|
||||
{
|
||||
get => (bool)GetValue(IsSelectingProperty);
|
||||
internal set => SetValue(IsSelectingProperty, value);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public ScreenshotWindow(Screenshot screenshot)
|
||||
{
|
||||
Style = ResourceHelper.GetResource<Style>(ResourceToken.Window4ScreenshotStyle);
|
||||
_screenshot = screenshot;
|
||||
DataContext = this;
|
||||
|
||||
_screenshotWindowHandle = this.GetHandle();
|
||||
InteropMethods.EnableWindow(_screenshotWindowHandle, false);
|
||||
|
||||
Loaded += ScreenshotWindow_Loaded;
|
||||
Closed += ScreenshotWindow_Closed;
|
||||
}
|
||||
|
||||
public override void OnApplyTemplate()
|
||||
{
|
||||
base.OnApplyTemplate();
|
||||
|
||||
Canvas = GetTemplateChild(ElementCanvas) as InkCanvas;
|
||||
MaskAreaLeft = GetTemplateChild(ElementMaskAreaLeft) as FrameworkElement;
|
||||
MaskAreaTop = GetTemplateChild(ElementMaskAreaTop) as FrameworkElement;
|
||||
MaskAreaRight = GetTemplateChild(ElementMaskAreaRight) as FrameworkElement;
|
||||
MaskAreaBottom = GetTemplateChild(ElementMaskAreaBottom) as FrameworkElement;
|
||||
TargetArea = GetTemplateChild(ElementTargetArea) as FrameworkElement;
|
||||
TextSize = GetTemplateChild(ElementTextSize) as TextBlock;
|
||||
}
|
||||
|
||||
protected override void OnPreviewKeyDown(KeyEventArgs e)
|
||||
{
|
||||
if (e.Key == Key.Escape) Close();
|
||||
|
||||
if (IsDrawing)
|
||||
{
|
||||
switch (e.Key)
|
||||
{
|
||||
case Key.Left:
|
||||
{
|
||||
MoveTargetArea(MoveRect(_targetWindowRect, -1, rightFlag: -1));
|
||||
}
|
||||
break;
|
||||
case Key.Up:
|
||||
{
|
||||
MoveTargetArea(MoveRect(_targetWindowRect, bottomFlag: -1, topFlag: -1));
|
||||
}
|
||||
break;
|
||||
case Key.Right:
|
||||
{
|
||||
MoveTargetArea(MoveRect(_targetWindowRect, 1, rightFlag: 1));
|
||||
}
|
||||
break;
|
||||
case Key.Down:
|
||||
{
|
||||
MoveTargetArea(MoveRect(_targetWindowRect, bottomFlag: 1, topFlag: 1));
|
||||
}
|
||||
break;
|
||||
case Key.Enter:
|
||||
SaveScreenshot();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnPreviewMouseLeftButtonDown(MouseButtonEventArgs e) => _mousePointOld = e.GetPosition(this);
|
||||
|
||||
protected override void OnPreviewMouseDoubleClick(MouseButtonEventArgs e) => SaveScreenshot();
|
||||
|
||||
protected override void OnPreviewMouseMove(MouseEventArgs e)
|
||||
{
|
||||
if (e.LeftButton != MouseButtonState.Pressed)
|
||||
{
|
||||
UpdateStatus(e.GetPosition(TargetArea));
|
||||
return;
|
||||
}
|
||||
|
||||
var newPoint = Mouse.GetPosition(this);
|
||||
var offsetX = (int)(newPoint.X - _mousePointOld.X);
|
||||
var offsetY = (int)(newPoint.Y - _mousePointOld.Y);
|
||||
var rect = _targetWindowRect;
|
||||
|
||||
if (IsDrawing)
|
||||
{
|
||||
if (_canDrag)
|
||||
{
|
||||
rect.Left += offsetX;
|
||||
rect.Top += offsetY;
|
||||
rect.Right += offsetX;
|
||||
rect.Bottom += offsetY;
|
||||
}
|
||||
else
|
||||
{
|
||||
var leftAddend = offsetX * _flagArr[0];
|
||||
var topAddend = offsetY * _flagArr[1];
|
||||
var rightAddend = offsetX * _flagArr[2];
|
||||
var bottomAddend = offsetY * _flagArr[3];
|
||||
|
||||
rect.Left += leftAddend;
|
||||
rect.Top += topAddend;
|
||||
rect.Right += rightAddend;
|
||||
rect.Bottom += bottomAddend;
|
||||
|
||||
if (rect.Width < 0)
|
||||
{
|
||||
if (_flagArr[0] > 0)
|
||||
{
|
||||
_flagArr[0] = 0;
|
||||
_flagArr[2] = 1;
|
||||
rect.Left -= leftAddend;
|
||||
rightAddend = offsetX * _flagArr[2];
|
||||
rect.Right += rightAddend;
|
||||
}
|
||||
else if (_flagArr[2] > 0)
|
||||
{
|
||||
_flagArr[0] = 1;
|
||||
_flagArr[2] = 0;
|
||||
rect.Right -= rightAddend;
|
||||
leftAddend = offsetX * _flagArr[0];
|
||||
rect.Left += leftAddend;
|
||||
}
|
||||
}
|
||||
|
||||
if (rect.Height < 0)
|
||||
{
|
||||
if (_flagArr[1] > 0)
|
||||
{
|
||||
_flagArr[1] = 0;
|
||||
_flagArr[3] = 1;
|
||||
rect.Top -= topAddend;
|
||||
bottomAddend = offsetY * _flagArr[3];
|
||||
rect.Bottom += bottomAddend;
|
||||
}
|
||||
else if (_flagArr[3] > 0)
|
||||
{
|
||||
_flagArr[1] = 1;
|
||||
_flagArr[3] = 0;
|
||||
rect.Bottom -= bottomAddend;
|
||||
topAddend = offsetY * _flagArr[1];
|
||||
rect.Top += topAddend;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MoveTargetArea(rect);
|
||||
_mousePointOld = newPoint;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!IsSelecting && offsetX > 0 && offsetY > 0)
|
||||
{
|
||||
rect = new InteropValues.RECT((int)_mousePointOld.X, (int)_mousePointOld.Y, 0, 0);
|
||||
IsSelecting = true;
|
||||
}
|
||||
|
||||
if (IsSelecting)
|
||||
{
|
||||
MoveTargetArea(new InteropValues.RECT(rect.Left, rect.Top, rect.Left + offsetX, rect.Top + offsetY));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ScreenshotWindow_Closed(object sender, EventArgs e)
|
||||
{
|
||||
StopHooks();
|
||||
IsDrawing = false;
|
||||
|
||||
Loaded -= ScreenshotWindow_Loaded;
|
||||
Closed -= ScreenshotWindow_Closed;
|
||||
}
|
||||
|
||||
private void ScreenshotWindow_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Canvas.Background = new ImageBrush(GetDesktopSnapshot());
|
||||
StartHooks();
|
||||
InteropMethods.GetCursorPos(out var point);
|
||||
MoveElement2Point(point);
|
||||
}
|
||||
|
||||
private void UpdateStatus(Point point)
|
||||
{
|
||||
Cursor cursor;
|
||||
|
||||
var leftAbs = Math.Abs(point.X);
|
||||
var topAbs = Math.Abs(point.Y);
|
||||
var rightAbs = Math.Abs(point.X - TargetArea.Width);
|
||||
var downAbs = Math.Abs(point.Y - TargetArea.Height);
|
||||
|
||||
_canDrag = false;
|
||||
_flagArr[0] = 0;
|
||||
_flagArr[1] = 0;
|
||||
_flagArr[2] = 0;
|
||||
_flagArr[3] = 0;
|
||||
|
||||
if (leftAbs <= SnapLength)
|
||||
{
|
||||
if (topAbs > SnapLength)
|
||||
{
|
||||
if (downAbs > SnapLength)
|
||||
{
|
||||
// left
|
||||
cursor = Cursors.SizeWE;
|
||||
_flagArr[0] = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
//left bottom
|
||||
cursor = Cursors.SizeNESW;
|
||||
_flagArr[0] = 1;
|
||||
_flagArr[3] = 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// left top
|
||||
cursor = Cursors.SizeNWSE;
|
||||
_flagArr[0] = 1;
|
||||
_flagArr[1] = 1;
|
||||
}
|
||||
}
|
||||
else if (rightAbs > SnapLength)
|
||||
{
|
||||
if (topAbs > SnapLength)
|
||||
{
|
||||
if (downAbs > SnapLength)
|
||||
{
|
||||
if (TargetArea.IsMouseOver)
|
||||
{
|
||||
//drag
|
||||
cursor = Cursors.SizeAll;
|
||||
_canDrag = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
//out
|
||||
cursor = Cursors.Arrow;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//bottom
|
||||
cursor = Cursors.SizeNS;
|
||||
_flagArr[3] = 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//top
|
||||
cursor = Cursors.SizeNS;
|
||||
_flagArr[1] = 1;
|
||||
}
|
||||
}
|
||||
else if (rightAbs <= SnapLength)
|
||||
{
|
||||
if (topAbs > SnapLength)
|
||||
{
|
||||
if (downAbs > SnapLength)
|
||||
{
|
||||
//right
|
||||
cursor = Cursors.SizeWE;
|
||||
_flagArr[2] = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
//right bottom
|
||||
cursor = Cursors.SizeNWSE;
|
||||
_flagArr[2] = 1;
|
||||
_flagArr[3] = 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// right top
|
||||
cursor = Cursors.SizeNESW;
|
||||
_flagArr[1] = 1;
|
||||
_flagArr[2] = 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//out
|
||||
cursor = Cursors.Arrow;
|
||||
}
|
||||
|
||||
TargetArea.Cursor = cursor;
|
||||
}
|
||||
|
||||
private void StopHooks()
|
||||
{
|
||||
MouseHook.Stop();
|
||||
MouseHook.StatusChanged -= MouseHook_StatusChanged;
|
||||
}
|
||||
|
||||
private void StartHooks()
|
||||
{
|
||||
MouseHook.Start();
|
||||
MouseHook.StatusChanged += MouseHook_StatusChanged;
|
||||
}
|
||||
|
||||
private void MouseHook_StatusChanged(object sender, MouseHookEventArgs e)
|
||||
{
|
||||
switch (e.MessageType)
|
||||
{
|
||||
case MouseHookMessageType.MouseMove:
|
||||
MoveElement2Point(e.Point);
|
||||
break;
|
||||
case MouseHookMessageType.LeftButtonDown:
|
||||
_receiveMoveMsg = false;
|
||||
_mousePointOld = new Point(e.Point.X, e.Point.Y);
|
||||
InteropMethods.EnableWindow(_screenshotWindowHandle, true);
|
||||
break;
|
||||
case MouseHookMessageType.LeftButtonUp:
|
||||
StopHooks();
|
||||
IsSelecting = false;
|
||||
IsDrawing = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void SaveScreenshot()
|
||||
{
|
||||
if (Canvas.Background is ImageBrush imageBrush && imageBrush.ImageSource is BitmapSource bitmapSource)
|
||||
{
|
||||
var cb = new CroppedBitmap(bitmapSource, new Int32Rect(_targetWindowRect.Left, _targetWindowRect.Top, _targetWindowRect.Width, _targetWindowRect.Height));
|
||||
_screenshot.Source = cb;
|
||||
}
|
||||
|
||||
_screenshot.OnSnapped();
|
||||
Close();
|
||||
}
|
||||
|
||||
private ImageSource GetDesktopSnapshot()
|
||||
{
|
||||
_desktopWindowHandle = InteropMethods.GetDesktopWindow();
|
||||
var hdcSrc = InteropMethods.GetWindowDC(_desktopWindowHandle);
|
||||
var hdcDest = InteropMethods.CreateCompatibleDC(hdcSrc);
|
||||
|
||||
InteropMethods.GetWindowRect(_desktopWindowHandle, out _desktopWindowRect);
|
||||
var desktopWindowWidth = _desktopWindowRect.Right - _desktopWindowRect.Left;
|
||||
var desktopWindowHeight = _desktopWindowRect.Bottom - _desktopWindowRect.Top;
|
||||
|
||||
var bitmap = InteropMethods.CreateCompatibleBitmap(hdcSrc, desktopWindowWidth, desktopWindowHeight);
|
||||
var hOld = InteropMethods.SelectObject(hdcDest, bitmap);
|
||||
InteropMethods.BitBlt(hdcDest, 0, 0, desktopWindowWidth, desktopWindowHeight, hdcSrc, 0, 0, InteropValues.SRCCOPY);
|
||||
InteropMethods.SelectObject(hdcDest, hOld);
|
||||
InteropMethods.DeleteDC(hdcDest);
|
||||
InteropMethods.ReleaseDC(_desktopWindowHandle, hdcSrc);
|
||||
return Imaging.CreateBitmapSourceFromHBitmap(bitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
|
||||
}
|
||||
|
||||
private void MoveElement2Point(InteropValues.POINT point)
|
||||
{
|
||||
if (!_receiveMoveMsg) return;
|
||||
|
||||
var mouseOverWindowHandle = InteropMethods.ChildWindowFromPointEx(_desktopWindowHandle,
|
||||
new InteropValues.POINT
|
||||
{
|
||||
X = point.X,
|
||||
Y = point.Y
|
||||
}, 1 | 2);
|
||||
|
||||
if (mouseOverWindowHandle != _mouseOverWindowHandle && mouseOverWindowHandle != IntPtr.Zero)
|
||||
{
|
||||
_mouseOverWindowHandle = mouseOverWindowHandle;
|
||||
|
||||
InteropMethods.GetWindowRect(_mouseOverWindowHandle, out var windowRect);
|
||||
MoveTargetArea(windowRect);
|
||||
}
|
||||
}
|
||||
|
||||
private void RegularRect(ref InteropValues.RECT rect)
|
||||
{
|
||||
if (rect.Left < 0)
|
||||
{
|
||||
rect.Right -= rect.Left;
|
||||
rect.Left = 0;
|
||||
}
|
||||
|
||||
if (rect.Top < 0)
|
||||
{
|
||||
rect.Bottom -= rect.Top;
|
||||
rect.Top = 0;
|
||||
}
|
||||
|
||||
if (rect.Right > _desktopWindowRect.Width)
|
||||
{
|
||||
rect.Left -= rect.Right - _desktopWindowRect.Width;
|
||||
rect.Right = _desktopWindowRect.Width;
|
||||
}
|
||||
|
||||
if (rect.Bottom > _desktopWindowRect.Height)
|
||||
{
|
||||
rect.Top -= rect.Bottom - _desktopWindowRect.Height;
|
||||
rect.Bottom = _desktopWindowRect.Height;
|
||||
}
|
||||
|
||||
rect.Left = Math.Max(0, rect.Left);
|
||||
rect.Top = Math.Max(0, rect.Top);
|
||||
}
|
||||
|
||||
private static InteropValues.RECT MoveRect(InteropValues.RECT rect, int leftFlag = 0, int topFlag = 0, int rightFlag = 0, int bottomFlag = 0)
|
||||
{
|
||||
var moveLength = Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl)
|
||||
? IntervalBigLength
|
||||
: IntervalLength;
|
||||
|
||||
rect.Left += leftFlag * moveLength;
|
||||
rect.Top += topFlag * moveLength;
|
||||
rect.Right += rightFlag * moveLength;
|
||||
rect.Bottom += bottomFlag * moveLength;
|
||||
|
||||
return rect;
|
||||
}
|
||||
|
||||
private void MoveTargetArea(InteropValues.RECT rect)
|
||||
{
|
||||
RegularRect(ref rect);
|
||||
|
||||
var width = rect.Width;
|
||||
var height = rect.Height;
|
||||
var left = rect.Left;
|
||||
var top = rect.Top;
|
||||
|
||||
TargetArea.Width = width;
|
||||
TargetArea.Height = height;
|
||||
TargetArea.Margin = new Thickness(left, top, 0, 0);
|
||||
|
||||
_targetWindowRect = new InteropValues.RECT(left, top, left + width, top + height);
|
||||
TextSize.Text = $"{_targetWindowRect.Width} x {_targetWindowRect.Height}";
|
||||
|
||||
MoveMaskArea();
|
||||
}
|
||||
|
||||
private void MoveMaskArea()
|
||||
{
|
||||
MaskAreaLeft.Width = TargetArea.Margin.Left;
|
||||
MaskAreaLeft.Height = _desktopWindowRect.Height;
|
||||
|
||||
MaskAreaTop.Margin = new Thickness(TargetArea.Margin.Left, 0, 0, 0);
|
||||
MaskAreaTop.Width = TargetArea.Width;
|
||||
MaskAreaTop.Height = TargetArea.Margin.Top;
|
||||
|
||||
MaskAreaRight.Margin = new Thickness(TargetArea.Width + TargetArea.Margin.Left, 0, 0, 0);
|
||||
MaskAreaRight.Width = _desktopWindowRect.Width - TargetArea.Margin.Left - TargetArea.Width;
|
||||
MaskAreaRight.Height = _desktopWindowRect.Height;
|
||||
|
||||
MaskAreaBottom.Margin = new Thickness(TargetArea.Margin.Left, TargetArea.Height + TargetArea.Margin.Top, 0, 0);
|
||||
MaskAreaBottom.Width = TargetArea.Width;
|
||||
MaskAreaBottom.Height = _desktopWindowRect.Height - TargetArea.Height - TargetArea.Margin.Top;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ namespace HandyControl.Data
|
||||
{
|
||||
internal class MouseHookEventArgs : EventArgs
|
||||
{
|
||||
public MouseHookMessageType Message { get; set; }
|
||||
public MouseHookMessageType MessageType { get; set; }
|
||||
|
||||
public InteropValues.POINT Point { get; set; }
|
||||
}
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
|
||||
namespace HandyControl.Data
|
||||
{
|
||||
public enum PlacementType
|
||||
{
|
||||
/// <summary>
|
||||
/// 左上
|
||||
/// </summary>
|
||||
LeftTop,
|
||||
|
||||
/// <summary>
|
||||
/// 左
|
||||
/// </summary>
|
||||
Left,
|
||||
|
||||
/// <summary>
|
||||
/// 左下
|
||||
/// </summary>
|
||||
LeftBottom,
|
||||
|
||||
/// <summary>
|
||||
/// 上左
|
||||
/// </summary>
|
||||
TopLeft,
|
||||
|
||||
/// <summary>
|
||||
/// 上
|
||||
/// </summary>
|
||||
Top,
|
||||
|
||||
/// <summary>
|
||||
/// 上右
|
||||
/// </summary>
|
||||
TopRight,
|
||||
|
||||
/// <summary>
|
||||
/// 右上
|
||||
/// </summary>
|
||||
RightTop,
|
||||
|
||||
/// <summary>
|
||||
/// 右
|
||||
/// </summary>
|
||||
Right,
|
||||
|
||||
/// <summary>
|
||||
/// 右下
|
||||
/// </summary>
|
||||
RightBottom,
|
||||
|
||||
/// <summary>
|
||||
/// 下左
|
||||
/// </summary>
|
||||
BottomLeft,
|
||||
|
||||
/// <summary>
|
||||
/// 下
|
||||
/// </summary>
|
||||
Bottom,
|
||||
|
||||
/// <summary>
|
||||
/// 下右
|
||||
/// </summary>
|
||||
BottomRight,
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
namespace HandyControl.Data
|
||||
{
|
||||
public enum TipPlacement
|
||||
public enum PlacementType
|
||||
{
|
||||
/// <summary>
|
||||
/// 左上
|
||||
|
||||
@@ -306,6 +306,8 @@
|
||||
|
||||
internal const string WindowGlow = nameof(WindowGlow);
|
||||
|
||||
internal const string Window4ScreenshotStyle = nameof(Window4ScreenshotStyle);
|
||||
|
||||
internal const string AddTagButtonStyle = nameof(AddTagButtonStyle);
|
||||
|
||||
internal const string RadioGroupItemDefault = nameof(RadioGroupItemDefault);
|
||||
@@ -355,7 +357,7 @@
|
||||
internal const string TabItemCapsuleVerticalFirst = nameof(TabItemCapsuleVerticalFirst);
|
||||
|
||||
internal const string TabItemCapsuleVerticalLast = nameof(TabItemCapsuleVerticalLast);
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -34,10 +34,12 @@
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Other\Card.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Other\Notification.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Other\Poptip.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Screenshot\Screenshot.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Other\Sprite.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Block\ToggleBlock.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Panel\HoneycombPanel.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Panel\RelativePanel.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Screenshot\ScreenshotWindow.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Slider\RangeSlider\RangeTrack.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Slider\RangeSlider\RangeThumb.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Slider\RangeSlider\TwoWayRangeBase.cs" />
|
||||
@@ -198,7 +200,7 @@
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Data\Enum\SkinType.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Data\Enum\StepStatus.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Data\Enum\TextType.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Data\Enum\TipPlacement.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Data\Enum\PlacementType.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Data\Enum\TitleAlignment.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Data\Gif\GifFrameDimension.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Data\Gif\GifImageInfo.cs" />
|
||||
@@ -248,9 +250,9 @@
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Expression\Shapes\PrimitiveShape.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Interactivity\AdornerContainer.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Interactivity\AttachableCollection!1.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Interactivity\Behavior!1.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Interactivity\Behavior.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Interactivity\BehaviorCollection.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Interactivity\Behavior\Behavior!1.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Interactivity\Behavior\Behavior.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Interactivity\Behavior\BehaviorCollection.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Interactivity\Commands\ControlCommands.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Interactivity\DefaultTriggerAttribute.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Interactivity\EventToCommand.cs" />
|
||||
@@ -259,14 +261,14 @@
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Interactivity\EventTriggerBase.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Interactivity\ExceptionStringTable.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Interactivity\ExtendedVisualStateManager.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Interactivity\FluidMoveBehavior.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Interactivity\FluidMoveBehaviorBase.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Interactivity\Behavior\FluidMoveBehavior.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Interactivity\Behavior\FluidMoveBehaviorBase.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Interactivity\FluidMoveScope.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Interactivity\IAttachedObject.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Interactivity\IEventArgsConverter.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Interactivity\Interaction.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Interactivity\InvokeCommandAction.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Interactivity\MouseDragElementBehavior.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Interactivity\Behavior\MouseDragElementBehavior.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Interactivity\NameResolvedEventArgs.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Interactivity\NameResolver.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Interactivity\PreviewInvokeEventArgs.cs" />
|
||||
@@ -333,7 +335,7 @@
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Tools\Interop\InteropValues.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Tools\Interop\Handle\SafeFileMappingHandle.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Tools\Interop\Handle\WpfSafeHandle.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Interactivity\MouseDragElementBehaviorEx.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Interactivity\Behavior\MouseDragElementBehaviorEx.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Tools\Pool\IPool!1.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Tools\Pool\SimplePool!1.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Tools\Pool\SynchronizedPool!1.cs" />
|
||||
@@ -404,6 +406,10 @@
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="$(MSBuildThisFileDirectory)Themes\Styles\Screenshot.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="$(MSBuildThisFileDirectory)Themes\Styles\BlendEffectBox.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -0,0 +1,125 @@
|
||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:controls="clr-namespace:HandyControl.Controls">
|
||||
|
||||
<Style x:Key="MaskRect4ScreenshotStyle" TargetType="Rectangle">
|
||||
<Setter Property="IsHitTestVisible" Value="False"/>
|
||||
<Setter Property="Fill" Value="{DynamicResource DarkOpacityBrush}"/>
|
||||
<Setter Property="HorizontalAlignment" Value="Left"/>
|
||||
<Setter Property="VerticalAlignment" Value="Top"/>
|
||||
</Style>
|
||||
|
||||
<Style x:Key="SnapRect4ScreenshotStyle" TargetType="Rectangle">
|
||||
<Setter Property="Height" Value="5"/>
|
||||
<Setter Property="Width" Value="5"/>
|
||||
<Setter Property="Fill" Value="DodgerBlue"/>
|
||||
<Setter Property="HorizontalAlignment" Value="Left"/>
|
||||
<Setter Property="VerticalAlignment" Value="Top"/>
|
||||
<Setter Property="Visibility" Value="Collapsed"/>
|
||||
<Style.Triggers>
|
||||
<Trigger Property="controls:TipElement.Placement" Value="LeftTop">
|
||||
<Setter Property="Margin" Value="-3, -3, 0, 0"/>
|
||||
<Setter Property="HorizontalAlignment" Value="Left"/>
|
||||
<Setter Property="VerticalAlignment" Value="Top"/>
|
||||
</Trigger>
|
||||
<Trigger Property="controls:TipElement.Placement" Value="Top">
|
||||
<Setter Property="Margin" Value="0, -3, 0, 0"/>
|
||||
<Setter Property="HorizontalAlignment" Value="Center"/>
|
||||
<Setter Property="VerticalAlignment" Value="Top"/>
|
||||
</Trigger>
|
||||
<Trigger Property="controls:TipElement.Placement" Value="RightTop">
|
||||
<Setter Property="Margin" Value="0, -3, -3, 0"/>
|
||||
<Setter Property="HorizontalAlignment" Value="Right"/>
|
||||
<Setter Property="VerticalAlignment" Value="Top"/>
|
||||
</Trigger>
|
||||
<Trigger Property="controls:TipElement.Placement" Value="Right">
|
||||
<Setter Property="Margin" Value="0, 0, -3, 0"/>
|
||||
<Setter Property="HorizontalAlignment" Value="Right"/>
|
||||
<Setter Property="VerticalAlignment" Value="Center"/>
|
||||
</Trigger>
|
||||
<Trigger Property="controls:TipElement.Placement" Value="RightBottom">
|
||||
<Setter Property="Margin" Value="0, 0, -3, -3"/>
|
||||
<Setter Property="HorizontalAlignment" Value="Right"/>
|
||||
<Setter Property="VerticalAlignment" Value="Bottom"/>
|
||||
</Trigger>
|
||||
<Trigger Property="controls:TipElement.Placement" Value="Bottom">
|
||||
<Setter Property="Margin" Value="0, 0, 0, -3"/>
|
||||
<Setter Property="HorizontalAlignment" Value="Center"/>
|
||||
<Setter Property="VerticalAlignment" Value="Bottom"/>
|
||||
</Trigger>
|
||||
<Trigger Property="controls:TipElement.Placement" Value="LeftBottom">
|
||||
<Setter Property="Margin" Value="-3, 0, 0, -3"/>
|
||||
<Setter Property="HorizontalAlignment" Value="Left"/>
|
||||
<Setter Property="VerticalAlignment" Value="Bottom"/>
|
||||
</Trigger>
|
||||
<Trigger Property="controls:TipElement.Placement" Value="Left">
|
||||
<Setter Property="Margin" Value="-3, 0, 0, 0"/>
|
||||
<Setter Property="HorizontalAlignment" Value="Left"/>
|
||||
<Setter Property="VerticalAlignment" Value="Center"/>
|
||||
</Trigger>
|
||||
<DataTrigger Binding="{Binding IsSelecting}" Value="True">
|
||||
<Setter Property="Visibility" Value="Visible"/>
|
||||
</DataTrigger>
|
||||
<DataTrigger Binding="{Binding IsDrawing}" Value="True">
|
||||
<Setter Property="Visibility" Value="Visible"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
|
||||
<Style x:Key="TargetArea4ScreenshotStyle" TargetType="Border">
|
||||
<Setter Property="IsHitTestVisible" Value="False"/>
|
||||
<Setter Property="BorderThickness" Value="5"/>
|
||||
<Setter Property="BorderBrush" Value="DodgerBlue"/>
|
||||
<Setter Property="Background" Value="Transparent"/>
|
||||
<Setter Property="HorizontalAlignment" Value="Left"/>
|
||||
<Setter Property="VerticalAlignment" Value="Top"/>
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding IsSelecting}" Value="True">
|
||||
<Setter Property="BorderThickness" Value="1"/>
|
||||
</DataTrigger>
|
||||
<DataTrigger Binding="{Binding IsDrawing}" Value="True">
|
||||
<Setter Property="IsHitTestVisible" Value="True"/>
|
||||
<Setter Property="BorderThickness" Value="1"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
|
||||
<Style x:Key="Window4ScreenshotStyle" TargetType="controls:ScreenshotWindow">
|
||||
<Setter Property="UseLayoutRounding" Value="True"/>
|
||||
<Setter Property="WindowStyle" Value="None"/>
|
||||
<Setter Property="WindowState" Value="Maximized"/>
|
||||
<!--<Setter Property="Topmost" Value="True"/>-->
|
||||
<Setter Property="AllowsTransparency" Value="True"/>
|
||||
<Setter Property="ResizeMode" Value="NoResize"/>
|
||||
<Setter Property="Background" Value="Transparent"/>
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="controls:ScreenshotWindow">
|
||||
<AdornerDecorator>
|
||||
<controls:SimplePanel>
|
||||
<InkCanvas EditingMode="None" Name="PART_Canvas" Background="Transparent"/>
|
||||
<Rectangle Name="PART_MaskAreaLeft" Style="{StaticResource MaskRect4ScreenshotStyle}"/>
|
||||
<Rectangle Name="PART_MaskAreaTop" Style="{StaticResource MaskRect4ScreenshotStyle}"/>
|
||||
<Rectangle Name="PART_MaskAreaRight" Style="{StaticResource MaskRect4ScreenshotStyle}"/>
|
||||
<Rectangle Name="PART_MaskAreaBottom" Style="{StaticResource MaskRect4ScreenshotStyle}"/>
|
||||
<Border Name="PART_TargetArea" Style="{StaticResource TargetArea4ScreenshotStyle}">
|
||||
<controls:SimplePanel>
|
||||
<Rectangle controls:TipElement.Placement="LeftTop" Style="{StaticResource SnapRect4ScreenshotStyle}"/>
|
||||
<Rectangle controls:TipElement.Placement="Top" Style="{StaticResource SnapRect4ScreenshotStyle}"/>
|
||||
<Rectangle controls:TipElement.Placement="RightTop" Style="{StaticResource SnapRect4ScreenshotStyle}"/>
|
||||
<Rectangle controls:TipElement.Placement="Right" Style="{StaticResource SnapRect4ScreenshotStyle}"/>
|
||||
<Rectangle controls:TipElement.Placement="RightBottom" Style="{StaticResource SnapRect4ScreenshotStyle}"/>
|
||||
<Rectangle controls:TipElement.Placement="Bottom" Style="{StaticResource SnapRect4ScreenshotStyle}"/>
|
||||
<Rectangle controls:TipElement.Placement="LeftBottom" Style="{StaticResource SnapRect4ScreenshotStyle}"/>
|
||||
<Rectangle controls:TipElement.Placement="Left" Style="{StaticResource SnapRect4ScreenshotStyle}"/>
|
||||
<TextBlock Name="PART_TextSize" Background="#CC212121" Foreground="White" HorizontalAlignment="Left" VerticalAlignment="Top" Padding="10,2"/>
|
||||
</controls:SimplePanel>
|
||||
</Border>
|
||||
</controls:SimplePanel>
|
||||
</AdornerDecorator>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
|
||||
</ResourceDictionary>
|
||||
@@ -85,6 +85,7 @@
|
||||
<ResourceDictionary Source="NavigationWindow.xaml"/>
|
||||
<ResourceDictionary Source="Frame.xaml"/>
|
||||
<ResourceDictionary Source="BlendEffectBox.xaml"/>
|
||||
<ResourceDictionary Source="Screenshot.xaml"/>
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
|
||||
</ResourceDictionary>
|
||||
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Collections.Specialized;
|
||||
using System.Windows;
|
||||
@@ -18,7 +17,6 @@ namespace HandyControl.Tools
|
||||
|
||||
static GlobalShortcut()
|
||||
{
|
||||
|
||||
KeyboardHook.KeyDown += KeyboardHook_KeyDown;
|
||||
}
|
||||
|
||||
@@ -51,21 +49,6 @@ namespace HandyControl.Tools
|
||||
key == Key.RightCtrl || key == Key.RightAlt || key == Key.RightShift || key == Key.RWin;
|
||||
}
|
||||
|
||||
[Obsolete("pls use Host attach property instead of Init method")]
|
||||
public static void Init(DependencyObject host)
|
||||
{
|
||||
CommandDic.Clear();
|
||||
|
||||
if (host == null) return;
|
||||
|
||||
KeyBindingCollection = GetKeyBindings(host);
|
||||
if (KeyBindingCollection == null || KeyBindingCollection.Count == 0) return;
|
||||
|
||||
AddKeyBindings(KeyBindingCollection);
|
||||
|
||||
KeyboardHook.Start();
|
||||
}
|
||||
|
||||
private static void AddKeyBindings(IEnumerable<KeyBinding> keyBindings)
|
||||
{
|
||||
foreach (var item in keyBindings)
|
||||
|
||||
@@ -6,7 +6,6 @@ using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
using System.Windows;
|
||||
using System.Windows.Interop;
|
||||
using HandyControl.Tools.Extension;
|
||||
using HandyControl.Tools.Interop;
|
||||
|
||||
namespace HandyControl.Tools
|
||||
|
||||
@@ -6,32 +6,43 @@ namespace HandyControl.Tools
|
||||
{
|
||||
public class ClipboardHook
|
||||
{
|
||||
public static event Action ContentChanged;
|
||||
|
||||
private static HwndSource HWndSource;
|
||||
|
||||
private static IntPtr HookId = IntPtr.Zero;
|
||||
|
||||
public static event Action ContentChanged;
|
||||
private static int Count;
|
||||
|
||||
public static void Start()
|
||||
{
|
||||
if (HookId != IntPtr.Zero)
|
||||
if (HookId == IntPtr.Zero)
|
||||
{
|
||||
Stop();
|
||||
HookId = WindowHelper.CreateHandle();
|
||||
HWndSource = HwndSource.FromHwnd(HookId);
|
||||
if (HWndSource != null)
|
||||
{
|
||||
HWndSource.AddHook(WinProc);
|
||||
InteropMethods.AddClipboardFormatListener(HookId);
|
||||
}
|
||||
}
|
||||
|
||||
HookId = WindowHelper.CreateHandle();
|
||||
HWndSource = HwndSource.FromHwnd(HookId);
|
||||
if (HWndSource != null)
|
||||
if (HookId != IntPtr.Zero)
|
||||
{
|
||||
HWndSource.AddHook(WinProc);
|
||||
InteropMethods.AddClipboardFormatListener(HookId);
|
||||
Count++;
|
||||
}
|
||||
}
|
||||
|
||||
public static void Stop()
|
||||
{
|
||||
HWndSource.RemoveHook(WinProc);
|
||||
InteropMethods.RemoveClipboardFormatListener(HookId);
|
||||
Count--;
|
||||
if (Count < 1)
|
||||
{
|
||||
HWndSource.RemoveHook(WinProc);
|
||||
InteropMethods.RemoveClipboardFormatListener(HookId);
|
||||
|
||||
HookId = IntPtr.Zero;
|
||||
}
|
||||
}
|
||||
|
||||
private static IntPtr WinProc(IntPtr hwnd, int msg, IntPtr wparam, IntPtr lparam, ref bool handled)
|
||||
|
||||
@@ -26,29 +26,42 @@ namespace HandyControl.Tools
|
||||
|
||||
private static readonly IntPtr SyskeyUpIntPtr = (IntPtr)InteropValues.WM_SYSKEYUP;
|
||||
|
||||
private static int Count;
|
||||
|
||||
public static void Start()
|
||||
{
|
||||
if (HookId == IntPtr.Zero)
|
||||
{
|
||||
HookId = SetHook(Proc);
|
||||
}
|
||||
|
||||
if (HookId != IntPtr.Zero)
|
||||
{
|
||||
Stop();
|
||||
Count++;
|
||||
}
|
||||
HookId = SetHook(Proc);
|
||||
}
|
||||
|
||||
public static void Stop() => InteropMethods.UnhookWindowsHookEx(HookId);
|
||||
public static void Stop()
|
||||
{
|
||||
Count--;
|
||||
if (Count < 1)
|
||||
{
|
||||
InteropMethods.UnhookWindowsHookEx(HookId);
|
||||
HookId = IntPtr.Zero;
|
||||
}
|
||||
}
|
||||
|
||||
private static IntPtr SetHook(InteropValues.HookProc proc)
|
||||
{
|
||||
using (var curProcess = Process.GetCurrentProcess())
|
||||
using (var curModule = curProcess.MainModule)
|
||||
using var curProcess = Process.GetCurrentProcess();
|
||||
using var curModule = curProcess.MainModule;
|
||||
|
||||
if (curModule != null)
|
||||
{
|
||||
if (curModule != null)
|
||||
{
|
||||
return InteropMethods.SetWindowsHookEx((int)InteropValues.HookType.WH_KEYBOARD_LL, proc,
|
||||
InteropMethods.GetModuleHandle(curModule.ModuleName), 0);
|
||||
}
|
||||
return IntPtr.Zero;
|
||||
return InteropMethods.SetWindowsHookEx((int)InteropValues.HookType.WH_KEYBOARD_LL, proc,
|
||||
InteropMethods.GetModuleHandle(curModule.ModuleName), 0);
|
||||
}
|
||||
return IntPtr.Zero;
|
||||
}
|
||||
|
||||
private static IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam)
|
||||
|
||||
@@ -14,29 +14,42 @@ namespace HandyControl.Tools
|
||||
|
||||
private static readonly InteropValues.HookProc Proc = HookCallback;
|
||||
|
||||
private static int Count;
|
||||
|
||||
public static void Start()
|
||||
{
|
||||
if (HookId == IntPtr.Zero)
|
||||
{
|
||||
HookId = SetHook(Proc);
|
||||
}
|
||||
|
||||
if (HookId != IntPtr.Zero)
|
||||
{
|
||||
Stop();
|
||||
Count++;
|
||||
}
|
||||
HookId = SetHook(Proc);
|
||||
}
|
||||
|
||||
public static void Stop() => InteropMethods.UnhookWindowsHookEx(HookId);
|
||||
public static void Stop()
|
||||
{
|
||||
Count--;
|
||||
if (Count < 1)
|
||||
{
|
||||
InteropMethods.UnhookWindowsHookEx(HookId);
|
||||
HookId = IntPtr.Zero;
|
||||
}
|
||||
}
|
||||
|
||||
private static IntPtr SetHook(InteropValues.HookProc proc)
|
||||
{
|
||||
using (var curProcess = Process.GetCurrentProcess())
|
||||
using (var curModule = curProcess.MainModule)
|
||||
using var curProcess = Process.GetCurrentProcess();
|
||||
using var curModule = curProcess.MainModule;
|
||||
|
||||
if (curModule != null)
|
||||
{
|
||||
if (curModule != null)
|
||||
{
|
||||
return InteropMethods.SetWindowsHookEx((int)InteropValues.HookType.WH_MOUSE_LL, proc,
|
||||
InteropMethods.GetModuleHandle(curModule.ModuleName), 0);
|
||||
}
|
||||
return IntPtr.Zero;
|
||||
return InteropMethods.SetWindowsHookEx((int)InteropValues.HookType.WH_MOUSE_LL, proc,
|
||||
InteropMethods.GetModuleHandle(curModule.ModuleName), 0);
|
||||
}
|
||||
return IntPtr.Zero;
|
||||
}
|
||||
|
||||
private static IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam)
|
||||
@@ -45,7 +58,7 @@ namespace HandyControl.Tools
|
||||
var hookStruct = (InteropValues.MOUSEHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(InteropValues.MOUSEHOOKSTRUCT));
|
||||
StatusChanged?.Invoke(null, new MouseHookEventArgs
|
||||
{
|
||||
Message = (MouseHookMessageType)wParam,
|
||||
MessageType = (MouseHookMessageType)wParam,
|
||||
Point = new InteropValues.POINT(hookStruct.pt.X, hookStruct.pt.Y)
|
||||
});
|
||||
|
||||
|
||||
@@ -239,11 +239,6 @@ namespace HandyControl.Tools.Interop
|
||||
IntPtr hInstance,
|
||||
IntPtr lpParam);
|
||||
|
||||
[SecurityCritical]
|
||||
[SuppressUnmanagedCodeSecurity]
|
||||
[DllImport(InteropValues.ExternDll.User32, CharSet = CharSet.Unicode, SetLastError = true, BestFitMapping = false)]
|
||||
internal static extern short RegisterClass(InteropValues.WNDCLASS wc);
|
||||
|
||||
[SecurityCritical]
|
||||
[SuppressUnmanagedCodeSecurity]
|
||||
[DllImport(InteropValues.ExternDll.User32, CharSet = CharSet.Unicode, SetLastError = true, BestFitMapping = false)]
|
||||
@@ -438,5 +433,18 @@ namespace HandyControl.Tools.Interop
|
||||
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;
|
||||
|
||||
[DllImport(InteropValues.ExternDll.User32)]
|
||||
internal static extern IntPtr ChildWindowFromPointEx(IntPtr hwndParent, InteropValues.POINT pt, int uFlags);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.Gdi32)]
|
||||
internal static extern IntPtr CreateCompatibleBitmap(IntPtr hDC, int width, int height);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.Gdi32)]
|
||||
internal static extern bool BitBlt(IntPtr hDC, int x, int y, int nWidth, int nHeight, IntPtr hSrcDC, int xSrc, int ySrc, int dwRop);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.User32)]
|
||||
[ResourceExposure(ResourceScope.None)]
|
||||
internal static extern bool EnableWindow(IntPtr hWnd, bool enable);
|
||||
}
|
||||
}
|
||||
@@ -80,7 +80,8 @@ namespace HandyControl.Tools.Interop
|
||||
SC_MOVE = 0xF010,
|
||||
SC_MINIMIZE = 0xF020,
|
||||
SC_MAXIMIZE = 0xF030,
|
||||
SC_RESTORE = 0xF120;
|
||||
SC_RESTORE = 0xF120,
|
||||
SRCCOPY = 0x00CC0020;
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
|
||||
internal class NOTIFYICONDATA
|
||||
@@ -212,6 +213,14 @@ namespace HandyControl.Tools.Interop
|
||||
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;
|
||||
|
||||
Reference in new issue
Block a user