From c17e86ca555d0905536500d58691be8a17b4bb48 Mon Sep 17 00:00:00 2001
From: NaBian <836904362@qq.com>
Date: Tue, 15 Dec 2020 12:37:25 +0800
Subject: [PATCH] delete redundant codes
---
.../Properties/Langs/Lang.ca-ES.resx | 3 +
.../Properties/Langs/Lang.en.resx | 3 +
.../Properties/Langs/Lang.fa.resx | 3 +
.../Properties/Langs/Lang.fr.resx | 3 +
.../Properties/Langs/Lang.ko-KR.resx | 3 +
.../Properties/Langs/Lang.pt-BR.resx | 3 +
.../Properties/Langs/Lang.ru.resx | 3 +
.../Properties/Langs/Lang.tr.resx | 3 +
.../Properties/Langs/LangProvider.cs | 1 +
.../Window/TouchDragMoveWindow.xaml.cs | 16 +-
.../Tools/Helper/TouchDragMoveWindowHelper.cs | 564 ++----------------
.../Tools/Helper/WindowHelper.cs | 18 +-
.../Tools/Interop/InteropValues.cs | 106 +++-
13 files changed, 191 insertions(+), 538 deletions(-)
diff --git a/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.ca-ES.resx b/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.ca-ES.resx
index 4591a16a..b2d5dbf5 100644
--- a/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.ca-ES.resx
+++ b/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.ca-ES.resx
@@ -765,4 +765,7 @@
TransitioningContentControl
+
+ open touch drag move window
+
\ No newline at end of file
diff --git a/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.en.resx b/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.en.resx
index 4747203a..2669203c 100644
--- a/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.en.resx
+++ b/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.en.resx
@@ -765,4 +765,7 @@
FlexPanel
+
+ open touch drag move window
+
\ No newline at end of file
diff --git a/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.fa.resx b/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.fa.resx
index efea38f5..980f7bb1 100644
--- a/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.fa.resx
+++ b/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.fa.resx
@@ -765,4 +765,7 @@
FlexPanel
+
+ open touch drag move window
+
\ No newline at end of file
diff --git a/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.fr.resx b/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.fr.resx
index 482c5abf..202b03a1 100644
--- a/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.fr.resx
+++ b/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.fr.resx
@@ -765,4 +765,7 @@
FlexPanel
+
+ open touch drag move window
+
\ No newline at end of file
diff --git a/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.ko-KR.resx b/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.ko-KR.resx
index 6191028d..4e54bdc6 100644
--- a/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.ko-KR.resx
+++ b/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.ko-KR.resx
@@ -765,4 +765,7 @@
FlexPanel
+
+ open touch drag move window
+
\ No newline at end of file
diff --git a/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.pt-BR.resx b/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.pt-BR.resx
index 80a0b183..75a14cb9 100644
--- a/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.pt-BR.resx
+++ b/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.pt-BR.resx
@@ -765,4 +765,7 @@
FlexPanel
+
+ open touch drag move window
+
\ No newline at end of file
diff --git a/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.ru.resx b/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.ru.resx
index 4747203a..2669203c 100644
--- a/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.ru.resx
+++ b/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.ru.resx
@@ -765,4 +765,7 @@
FlexPanel
+
+ open touch drag move window
+
\ No newline at end of file
diff --git a/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.tr.resx b/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.tr.resx
index 69d3a759..95e9c5ad 100644
--- a/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.tr.resx
+++ b/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.tr.resx
@@ -765,4 +765,7 @@
FlexPanel
+
+ open touch drag move window
+
\ No newline at end of file
diff --git a/src/Shared/HandyControlDemo_Shared/Properties/Langs/LangProvider.cs b/src/Shared/HandyControlDemo_Shared/Properties/Langs/LangProvider.cs
index ea95007e..7c692be2 100644
--- a/src/Shared/HandyControlDemo_Shared/Properties/Langs/LangProvider.cs
+++ b/src/Shared/HandyControlDemo_Shared/Properties/Langs/LangProvider.cs
@@ -162,6 +162,7 @@ namespace HandyControlDemo.Properties.Langs
OnPropertyChanged(nameof(OpenMouseFollowWindow));
OnPropertyChanged(nameof(OpenNativeCommonWindow));
OnPropertyChanged(nameof(OpenNavigationWindow));
+ OnPropertyChanged(nameof(OpenTouchDragMoveWindow));
OnPropertyChanged(nameof(OpenNoNonClientAreaDragableWindow));
OnPropertyChanged(nameof(OpenPanel));
OnPropertyChanged(nameof(OpenSprite));
diff --git a/src/Shared/HandyControlDemo_Shared/Window/TouchDragMoveWindow.xaml.cs b/src/Shared/HandyControlDemo_Shared/Window/TouchDragMoveWindow.xaml.cs
index f21ac8e1..c767502c 100644
--- a/src/Shared/HandyControlDemo_Shared/Window/TouchDragMoveWindow.xaml.cs
+++ b/src/Shared/HandyControlDemo_Shared/Window/TouchDragMoveWindow.xaml.cs
@@ -1,11 +1,12 @@
-using System.Windows;
-using System.Windows.Input;
-using HandyControl.Tools.Helper;
+using System.Windows.Input;
+using HandyControl.Tools;
namespace HandyControlDemo.Window
{
public partial class TouchDragMoveWindow
{
+ private int _currentTouchCount;
+
public TouchDragMoveWindow()
{
InitializeComponent();
@@ -23,14 +24,9 @@ namespace HandyControlDemo.Window
{
CaptureTouch(e.TouchDevice);
- if (_currentTouchCount == 0)
- {
- TouchDragMoveWindowHelper.DragMove(this);
- }
+ if (_currentTouchCount == 0) this.TouchDragMove();
_currentTouchCount++;
}
-
- private uint _currentTouchCount;
}
-}
+}
\ No newline at end of file
diff --git a/src/Shared/HandyControl_Shared/Tools/Helper/TouchDragMoveWindowHelper.cs b/src/Shared/HandyControl_Shared/Tools/Helper/TouchDragMoveWindowHelper.cs
index 59117c9b..ae24727f 100644
--- a/src/Shared/HandyControl_Shared/Tools/Helper/TouchDragMoveWindowHelper.cs
+++ b/src/Shared/HandyControl_Shared/Tools/Helper/TouchDragMoveWindowHelper.cs
@@ -1,535 +1,73 @@
-using System;
-using System.Diagnostics;
-using System.Globalization;
-using System.Runtime.InteropServices;
+//blog: https://blog.lindexi.com/post/WPF-%E5%A4%9A%E6%8C%87%E8%A7%A6%E6%91%B8%E6%8B%96%E6%8B%BD%E7%AA%97%E5%8F%A3-%E6%8B%96%E5%8A%A8%E4%BF%AE%E6%94%B9%E7%AA%97%E5%8F%A3%E5%9D%90%E6%A0%87.html
+
+using System;
using System.Windows;
using System.Windows.Input;
using System.Windows.Interop;
+using HandyControl.Tools.Interop;
namespace HandyControl.Tools.Helper
{
- ///
- /// 使用触摸拖动窗口的辅助类
- ///
- ///
- /// 细节请看 [WPF 多指触摸拖拽窗口 拖动修改窗口坐标](https://blog.lindexi.com/post/WPF-%E5%A4%9A%E6%8C%87%E8%A7%A6%E6%91%B8%E6%8B%96%E6%8B%BD%E7%AA%97%E5%8F%A3-%E6%8B%96%E5%8A%A8%E4%BF%AE%E6%94%B9%E7%AA%97%E5%8F%A3%E5%9D%90%E6%A0%87.html)
- ///
- public static class TouchDragMoveWindowHelper
+ internal class TouchDragMoveWindowHelper
{
- ///
- /// 开始使用触摸拖动窗口,在触摸抬起后自动结束
- ///
- ///
- public static void DragMove(Window window)
+ private const int MaxMoveSpeed = 60;
+
+ public TouchDragMoveWindowHelper(Window window)
{
- var dragMoveMode = new DragMoveMode(window);
- dragMoveMode.Start();
+ _window = window;
}
- class DragMoveMode
+ public void Start()
{
- public DragMoveMode(Window window)
+ var window = _window;
+
+ window.PreviewMouseMove += Window_PreviewMouseMove;
+ window.PreviewMouseUp += Window_PreviewMouseUp;
+ window.LostMouseCapture += Window_LostMouseCapture;
+ }
+
+ public void Stop()
+ {
+ var window = _window;
+
+ window.PreviewMouseMove -= Window_PreviewMouseMove;
+ window.PreviewMouseUp -= Window_PreviewMouseUp;
+ window.LostMouseCapture -= Window_LostMouseCapture;
+ }
+
+ private readonly Window _window;
+
+ private InteropValues.POINT? _lastPoint;
+
+ private void Window_LostMouseCapture(object sender, MouseEventArgs e) => Stop();
+
+ private void Window_PreviewMouseUp(object sender, MouseButtonEventArgs e) => Stop();
+
+ private void Window_PreviewMouseMove(object sender, MouseEventArgs e)
+ {
+ InteropMethods.GetCursorPos(out var lpPoint);
+
+ if (_lastPoint == null)
{
- _window = window;
- }
-
- public void Start()
- {
- var window = _window;
-
- window.PreviewMouseMove += Window_PreviewMouseMove;
- window.PreviewMouseUp += Window_PreviewMouseUp;
- window.LostMouseCapture += Window_LostMouseCapture;
- }
-
- public void Stop()
- {
- Window window = _window;
-
- window.PreviewMouseMove -= Window_PreviewMouseMove;
- window.PreviewMouseUp -= Window_PreviewMouseUp;
- window.LostMouseCapture -= Window_LostMouseCapture;
- }
-
- private readonly Window _window;
-
- private Win32.User32.Point? _lastPoint;
-
- private void Window_LostMouseCapture(object sender, MouseEventArgs e)
- {
- Stop();
- }
-
- private void Window_PreviewMouseUp(object sender, MouseButtonEventArgs e)
- {
- Stop();
- }
-
- private void Window_PreviewMouseMove(object sender, MouseEventArgs e)
- {
- Win32.User32.GetCursorPos(out var lpPoint);
-
- if (_lastPoint == null)
- {
- _lastPoint = lpPoint;
- _window.CaptureMouse();
- }
-
- var dx = lpPoint.X - _lastPoint.Value.X;
- var dy = lpPoint.Y - _lastPoint.Value.Y;
-
- Debug.WriteLine($"dx={dx} dy={dy}");
-
- // 以下的 60 是表示最大移动速度
- if (Math.Abs(dx) < 60 && Math.Abs(dy) < 60)
- {
- var handle = new WindowInteropHelper(_window).Handle;
-
- Win32.User32.GetWindowRect(handle, out var lpRect);
-
- Win32.User32.SetWindowPos(handle, IntPtr.Zero, lpRect.Left + dx, lpRect.Top + dy, 0, 0,
- (int)(Win32.User32.WindowPositionFlags.SWP_NOSIZE |
- Win32.User32.WindowPositionFlags.SWP_NOZORDER));
- }
-
_lastPoint = lpPoint;
+ _window.CaptureMouse();
}
- }
- private static class Win32
- {
- public static class User32
+ var dx = lpPoint.X - _lastPoint.Value.X;
+ var dy = lpPoint.Y - _lastPoint.Value.Y;
+
+ if (Math.Abs(dx) < MaxMoveSpeed && Math.Abs(dy) < MaxMoveSpeed)
{
- ///
- /// 改变一个子窗口、弹出式窗口和顶层窗口的尺寸、位置和 Z 序。
- ///
- /// 窗口句柄。
- ///
- /// 在z序中的位于被置位的窗口前的窗口句柄。该参数必须为一个窗口句柄,或下列值之一:
- /// HWND_BOTTOM:将窗口置于 Z 序的底部。如果参数hWnd标识了一个顶层窗口,则窗口失去顶级位置,并且被置在其他窗口的底部。
- /// HWND_NOTOPMOST:将窗口置于所有非顶层窗口之上(即在所有顶层窗口之后)。如果窗口已经是非顶层窗口则该标志不起作用。
- /// HWND_TOP:将窗口置于Z序的顶部。
- /// HWND_TOPMOST:将窗口置于所有非顶层窗口之上。即使窗口未被激活窗口也将保持顶级位置。
- ///
- /// 以客户坐标指定窗口新位置的左边界。
- /// 以客户坐标指定窗口新位置的顶边界。
- /// 以像素指定窗口的新的宽度。
- /// 以像素指定窗口的新的高度。
- ///
- /// 窗口尺寸和定位的标志。该参数可以是下列值的组合:
- /// SWP_ASYNCWINDOWPOS:如果调用进程不拥有窗口,系统会向拥有窗口的线程发出需求。这就防止调用线程在其他线程处理需求的时候发生死锁。
- /// SWP_DEFERERASE:防止产生 WM_SYNCPAINT 消息。
- /// SWP_DRAWFRAME:在窗口周围画一个边框(定义在窗口类描述中)。
- /// SWP_FRAMECHANGED:给窗口发送 WM_NCCALCSIZE 消息,即使窗口尺寸没有改变也会发送该消息。如果未指定这个标志,只有在改变了窗口尺寸时才发送 WM_NCCALCSIZE。
- /// SWP_HIDEWINDOW:隐藏窗口。
- /// SWP_NOACTIVATE:不激活窗口。如果未设置标志,则窗口被激活,并被设置到其他最高级窗口或非最高级组的顶部(根据参数hWndlnsertAfter设置)。
- /// SWP_NOCOPYBITS:清除客户区的所有内容。如果未设置该标志,客户区的有效内容被保存并且在窗口尺寸更新和重定位后拷贝回客户区。
- /// SWP_NOMOVE:维持当前位置(忽略X和Y参数)。
- /// SWP_NOOWNERZORDER:不改变 Z 序中的所有者窗口的位置。
- /// SWP_NOREDRAW:不重画改变的内容。如果设置了这个标志,则不发生任何重画动作。适用于客户区和非客户区(包括标题栏和滚动条)和任何由于窗回移动而露出的父窗口的所有部分。如果设置了这个标志,应用程序必须明确地使窗口无效并区重画窗口的任何部分和父窗口需要重画的部分。
- /// SWP_NOREPOSITION:与 SWP_NOOWNERZORDER 标志相同。
- /// SWP_NOSENDCHANGING:防止窗口接收 WM_WINDOWPOSCHANGING 消息。
- /// SWP_NOSIZE:维持当前尺寸(忽略 cx 和 cy 参数)。
- /// SWP_NOZORDER:维持当前 Z 序(忽略 hWndlnsertAfter 参数)。
- /// SWP_SHOWWINDOW:显示窗口。
- ///
- /// 如果函数成功,返回值为非零;如果函数失败,返回值为零。若想获得更多错误消息,请调用 GetLastError 函数。
- [DllImport(LibraryName, ExactSpelling = true, SetLastError = true)]
- public static extern Int32 SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, Int32 x, Int32 y, Int32 cx,
- Int32 cy, Int32 wFlagslong);
+ var handle = new WindowInteropHelper(_window).Handle;
- [Flags]
- public enum WindowPositionFlags
- {
- ///
- /// If the calling thread and the thread that owns the window are attached to different input queues, the system posts
- /// the request to the thread that owns the window. This prevents the calling thread from blocking its execution while
- /// other threads process the request.
- ///
- SWP_ASYNCWINDOWPOS = 0x4000,
+ InteropMethods.GetWindowRect(handle, out var lpRect);
- ///
- /// Prevents generation of the WM_SYNCPAINT message.
- ///
- SWP_DEFERERASE = 0x2000,
-
- ///
- /// Draws a frame (defined in the window's class description) around the window.
- ///
- SWP_DRAWFRAME = 0x0020,
-
- ///
- /// Applies new frame styles set using the SetWindowLong function. Sends a WM_NCCALCSIZE message to the window, even if
- /// the window's size is not being changed. If this flag is not specified, WM_NCCALCSIZE is sent only when the window's
- /// size is being changed.
- ///
- SWP_FRAMECHANGED = 0x0020,
-
- ///
- /// Hides the window.
- ///
- SWP_HIDEWINDOW = 0x0080,
-
- ///
- /// Does not activate the window. If this flag is not set, the window is activated and moved to the top of either the
- /// topmost or non-topmost group (depending on the setting of the hWndInsertAfter parameter).
- ///
- SWP_NOACTIVATE = 0x0010,
-
- ///
- /// Discards the entire contents of the client area. If this flag is not specified, the valid contents of the client
- /// area are saved and copied back into the client area after the window is sized or repositioned.
- ///
- SWP_NOCOPYBITS = 0x0100,
-
- ///
- /// Retains the current position (ignores X and Y parameters).
- ///
- SWP_NOMOVE = 0x0002,
-
- ///
- /// Does not change the owner window's position in the Z order.
- ///
- SWP_NOOWNERZORDER = 0x0200,
-
- ///
- /// Does not redraw changes. If this flag is set, no repainting of any kind occurs. This applies to the client area,
- /// the nonclient area (including the title bar and scroll bars), and any part of the parent window uncovered as a
- /// result of the window being moved. When this flag is set, the application must explicitly invalidate or redraw any
- /// parts of the window and parent window that need redrawing.
- ///
- SWP_NOREDRAW = 0x0008,
-
- ///
- /// Same as the SWP_NOOWNERZORDER flag.
- ///
- SWP_NOREPOSITION = 0x0200,
-
- ///
- /// Prevents the window from receiving the WM_WINDOWPOSCHANGING message.
- ///
- SWP_NOSENDCHANGING = 0x0400,
-
- ///
- /// Retains the current size (ignores the cx and cy parameters).
- ///
- SWP_NOSIZE = 0x0001,
-
- ///
- /// Retains the current Z order (ignores the hWndInsertAfter parameter).
- ///
- SWP_NOZORDER = 0x0004,
-
- ///
- /// Displays the window.
- ///
- SWP_SHOWWINDOW = 0x0040
- }
-
-
- public const string LibraryName = "user32";
-
- ///
- /// 获取的是以屏幕为坐标轴窗口坐标
- ///
- ///
- ///
- ///
- [return: MarshalAs(UnmanagedType.Bool)]
- [DllImport(LibraryName, ExactSpelling = true)]
- public static extern bool GetWindowRect(IntPtr hWnd, out Rectangle lpRect);
-
- ///
- /// 在 Win32 函数使用的矩形
- ///
- [StructLayout(LayoutKind.Sequential)]
- public partial struct Rectangle : IEquatable
- {
- ///
- /// 创建在 Win32 函数使用的矩形
- ///
- ///
- ///
- ///
- ///
- public Rectangle(int left = 0, int top = 0, int right = 0, int bottom = 0)
- {
- Left = left;
- Top = top;
- Right = right;
- Bottom = bottom;
- }
-
- ///
- /// 创建在 Win32 函数使用的矩形
- ///
- /// 矩形的宽度
- /// 矩形的高度
- public Rectangle(int width = 0, int height = 0) : this(0, 0, width, height)
- {
- }
-
- public int Left;
- public int Top;
- public int Right;
- public int Bottom;
-
- public bool Equals(Rectangle other)
- {
- return (Left == other.Left) && (Right == other.Right) && (Top == other.Top) &&
- (Bottom == other.Bottom);
- }
-
- public override bool Equals(object obj)
- {
- return obj is Rectangle && Equals((Rectangle)obj);
- }
-
- public static bool operator ==(Rectangle left, Rectangle right)
- {
- return left.Equals(right);
- }
-
- public static bool operator !=(Rectangle left, Rectangle right)
- {
- return !(left == right);
- }
-
- public override int GetHashCode()
- {
- unchecked
- {
- var hashCode = (int)Left;
- hashCode = (hashCode * 397) ^ (int)Top;
- hashCode = (hashCode * 397) ^ (int)Right;
- hashCode = (hashCode * 397) ^ (int)Bottom;
- return hashCode;
- }
- }
-
- ///
- /// 获取当前矩形是否空矩形
- ///
- public bool IsEmpty => this.Left == 0 && this.Top == 0 && this.Right == 0 && this.Bottom == 0;
-
- ///
- /// 矩形的宽度
- ///
- public int Width
- {
- get { return unchecked((int)(Right - Left)); }
- set { Right = unchecked((int)(Left + value)); }
- }
-
- ///
- /// 矩形的高度
- ///
- public int Height
- {
- get { return unchecked((int)(Bottom - Top)); }
- set { Bottom = unchecked((int)(Top + value)); }
- }
-
- ///
- /// 通过 x、y 坐标和宽度高度创建矩形
- ///
- ///
- ///
- ///
- ///
- ///
- public static Rectangle Create(int x, int y, int width, int height)
- {
- unchecked
- {
- return new Rectangle(x, y, (int)(width + x), (int)(height + y));
- }
- }
-
- public override string ToString()
- {
- var culture = CultureInfo.CurrentCulture;
- return
- $"{{ Left = {Left.ToString(culture)}, Top = {Top.ToString(culture)} , Right = {Right.ToString(culture)}, Bottom = {Bottom.ToString(culture)} }}, {{ Width: {Width.ToString(culture)}, Height: {Height.ToString(culture)} }}";
- }
-
- public static Rectangle From(ref Rectangle lvalue, ref Rectangle rvalue,
- Func leftTopOperation,
- Func rightBottomOperation = null)
- {
- if (rightBottomOperation == null)
- rightBottomOperation = leftTopOperation;
- return new Rectangle(
- leftTopOperation(lvalue.Left, rvalue.Left),
- leftTopOperation(lvalue.Top, rvalue.Top),
- rightBottomOperation(lvalue.Right, rvalue.Right),
- rightBottomOperation(lvalue.Bottom, rvalue.Bottom)
- );
- }
-
- public void Add(Rectangle value)
- {
- Add(ref this, ref value);
- }
-
- public void Subtract(Rectangle value)
- {
- Subtract(ref this, ref value);
- }
-
- public void Multiply(Rectangle value)
- {
- Multiply(ref this, ref value);
- }
-
- public void Divide(Rectangle value)
- {
- Divide(ref this, ref value);
- }
-
- public void Deflate(Rectangle value)
- {
- Deflate(ref this, ref value);
- }
-
- public void Inflate(Rectangle value)
- {
- Inflate(ref this, ref value);
- }
-
- public void Offset(int x, int y)
- {
- Offset(ref this, x, y);
- }
-
- public void OffsetTo(int x, int y)
- {
- OffsetTo(ref this, x, y);
- }
-
- public void Scale(int x, int y)
- {
- Scale(ref this, x, y);
- }
-
- public void ScaleTo(int x, int y)
- {
- ScaleTo(ref this, x, y);
- }
-
- public static void Add(ref Rectangle lvalue, ref Rectangle rvalue)
- {
- lvalue.Left += rvalue.Left;
- lvalue.Top += rvalue.Top;
- lvalue.Right += rvalue.Right;
- lvalue.Bottom += rvalue.Bottom;
- }
-
- public static void Subtract(ref Rectangle lvalue, ref Rectangle rvalue)
- {
- lvalue.Left -= rvalue.Left;
- lvalue.Top -= rvalue.Top;
- lvalue.Right -= rvalue.Right;
- lvalue.Bottom -= rvalue.Bottom;
- }
-
- public static void Multiply(ref Rectangle lvalue, ref Rectangle rvalue)
- {
- lvalue.Left *= rvalue.Left;
- lvalue.Top *= rvalue.Top;
- lvalue.Right *= rvalue.Right;
- lvalue.Bottom *= rvalue.Bottom;
- }
-
- public static void Divide(ref Rectangle lvalue, ref Rectangle rvalue)
- {
- lvalue.Left /= rvalue.Left;
- lvalue.Top /= rvalue.Top;
- lvalue.Right /= rvalue.Right;
- lvalue.Bottom /= rvalue.Bottom;
- }
-
- public static void Deflate(ref Rectangle target, ref Rectangle deflation)
- {
- target.Top += deflation.Top;
- target.Left += deflation.Left;
- target.Bottom -= deflation.Bottom;
- target.Right -= deflation.Right;
- }
-
- public static void Inflate(ref Rectangle target, ref Rectangle inflation)
- {
- target.Top -= inflation.Top;
- target.Left -= inflation.Left;
- target.Bottom += inflation.Bottom;
- target.Right += inflation.Right;
- }
-
- public static void Offset(ref Rectangle target, int x, int y)
- {
- target.Top += y;
- target.Left += x;
- target.Bottom += y;
- target.Right += x;
- }
-
- public static void OffsetTo(ref Rectangle target, int x, int y)
- {
- var width = target.Width;
- var height = target.Height;
- target.Left = x;
- target.Top = y;
- target.Right = width;
- target.Bottom = height;
- }
-
- public static void Scale(ref Rectangle target, int x, int y)
- {
- target.Top *= y;
- target.Left *= x;
- target.Bottom *= y;
- target.Right *= x;
- }
-
- public static void ScaleTo(ref Rectangle target, int x, int y)
- {
- unchecked
- {
- x = (int)(target.Left / x);
- y = (int)(target.Top / y);
- }
-
- Scale(ref target, x, y);
- }
- }
-
- [DllImport(LibraryName, SetLastError = true)]
- [return: MarshalAs(UnmanagedType.Bool)]
- public static extern bool GetCursorPos(out Point lpPoint);
-
- [StructLayout(LayoutKind.Sequential)]
- public struct Point
- {
- public int X;
- public int Y;
-
- public Point(int x, int y)
- {
- this.X = x;
- this.Y = y;
- }
-
- public static implicit operator System.Drawing.Point(Point p)
- {
- return new System.Drawing.Point(p.X, p.Y);
- }
-
- public static implicit operator Point(System.Drawing.Point p)
- {
- return new Point(p.X, p.Y);
- }
- }
+ InteropMethods.SetWindowPos(handle, IntPtr.Zero, lpRect.Left + dx, lpRect.Top + dy, 0, 0,
+ (int) (InteropValues.WindowPositionFlags.SWP_NOSIZE |
+ InteropValues.WindowPositionFlags.SWP_NOZORDER));
}
+
+ _lastPoint = lpPoint;
}
}
}
diff --git a/src/Shared/HandyControl_Shared/Tools/Helper/WindowHelper.cs b/src/Shared/HandyControl_Shared/Tools/Helper/WindowHelper.cs
index cf1c9c2b..e9c4d88e 100644
--- a/src/Shared/HandyControl_Shared/Tools/Helper/WindowHelper.cs
+++ b/src/Shared/HandyControl_Shared/Tools/Helper/WindowHelper.cs
@@ -7,6 +7,7 @@ using System.Security;
using System.Windows;
using System.Windows.Interop;
using HandyControl.Tools.Extension;
+using HandyControl.Tools.Helper;
using HandyControl.Tools.Interop;
namespace HandyControl.Tools
@@ -19,7 +20,7 @@ namespace HandyControl.Tools
///
public static Window GetActiveWindow() => Application.Current.Windows.OfType().SingleOrDefault(x => x.IsActive);
- private static readonly BitArray _cacheValid = new BitArray((int) InteropValues.CacheSlot.NumSlots);
+ private static readonly BitArray _cacheValid = new BitArray((int)InteropValues.CacheSlot.NumSlots);
private static bool _setDpiX = true;
@@ -90,7 +91,7 @@ namespace HandyControl.Tools
try
{
_dpiX = InteropMethods.GetDeviceCaps(new HandleRef(null, dc), InteropValues.LOGPIXELSX);
- _cacheValid[(int) InteropValues.CacheSlot.DpiX] = true;
+ _cacheValid[(int)InteropValues.CacheSlot.DpiX] = true;
}
finally
{
@@ -113,9 +114,9 @@ namespace HandyControl.Tools
{
lock (_cacheValid)
{
- while (!_cacheValid[(int) InteropValues.CacheSlot.WindowResizeBorderThickness])
+ while (!_cacheValid[(int)InteropValues.CacheSlot.WindowResizeBorderThickness])
{
- _cacheValid[(int) InteropValues.CacheSlot.WindowResizeBorderThickness] = true;
+ _cacheValid[(int)InteropValues.CacheSlot.WindowResizeBorderThickness] = true;
var frameSize = new Size(InteropMethods.GetSystemMetrics(InteropValues.SM.CXSIZEFRAME), InteropMethods.GetSystemMetrics(InteropValues.SM.CYSIZEFRAME));
var frameSizeInDips = DpiHelper.DeviceSizeToLogical(frameSize, DpiX / 96.0, Dpi / 96.0);
@@ -142,7 +143,7 @@ namespace HandyControl.Tools
InteropMethods.ReleaseDC(IntPtr.Zero, hdc);
return WindowResizeBorderThickness.Add(new Thickness((autoHide ? - 4 : 4) * scale));
#else
- return WindowResizeBorderThickness.Add(new Thickness(autoHide ? -4 : 4));
+ return WindowResizeBorderThickness.Add(new Thickness(autoHide ? - 4 : 4));
#endif
}
}
@@ -154,7 +155,7 @@ namespace HandyControl.Tools
public static HwndSource GetHwndSource(this Window window) => HwndSource.FromHwnd(window.GetHandle());
///
- /// 让窗口激活作为前台最上层窗口
+ /// 让窗口激活作为前台最上层窗口
///
///
public static void SetWindowToForeground(Window window)
@@ -189,5 +190,10 @@ namespace HandyControl.Tools
window.Topmost = false;
}
}
+
+ ///
+ /// 开始使用触摸拖动窗口,在触摸抬起后自动结束
+ ///
+ public static void TouchDragMove(this Window window) => new TouchDragMoveWindowHelper(window).Start();
}
}
diff --git a/src/Shared/HandyControl_Shared/Tools/Interop/InteropValues.cs b/src/Shared/HandyControl_Shared/Tools/Interop/InteropValues.cs
index 3b9c516b..d2c29d36 100644
--- a/src/Shared/HandyControl_Shared/Tools/Interop/InteropValues.cs
+++ b/src/Shared/HandyControl_Shared/Tools/Interop/InteropValues.cs
@@ -35,7 +35,7 @@ namespace HandyControl.Tools.Interop
PLANES = 14,
BI_RGB = 0,
DIB_RGB_COLORS = 0,
- E_FAIL = unchecked((int) 0x80004005),
+ E_FAIL = unchecked((int)0x80004005),
NIF_MESSAGE = 0x00000001,
NIF_ICON = 0x00000002,
NIF_TIP = 0x00000004,
@@ -233,10 +233,10 @@ namespace HandyControl.Tools.Interop
public RECT(Rect rect)
{
- Left = (int) rect.Left;
- Top = (int) rect.Top;
- Right = (int) rect.Right;
- Bottom = (int) rect.Bottom;
+ Left = (int)rect.Left;
+ Top = (int)rect.Top;
+ Right = (int)rect.Right;
+ Bottom = (int)rect.Bottom;
}
public Point Position => new Point(Left, Top);
@@ -717,11 +717,11 @@ namespace HandyControl.Tools.Interop
[return: MarshalAs(UnmanagedType.I8)]
long CopyTo([In, MarshalAs(UnmanagedType.Interface)] IStream pstm, [In, MarshalAs(UnmanagedType.I8)] long cb, [Out, MarshalAs(UnmanagedType.LPArray)] long[] pcbRead);
- void Commit([In] int grfCommitFlags);
+ void Commit([In]int grfCommitFlags);
void Revert();
- void LockRegion([In, MarshalAs(UnmanagedType.I8)] long libOffset, [In, MarshalAs(UnmanagedType.I8)] long cb, [In] int dwLockType);
+ void LockRegion([In, MarshalAs(UnmanagedType.I8)]long libOffset, [In, MarshalAs(UnmanagedType.I8)] long cb, [In] int dwLockType);
void UnlockRegion([In, MarshalAs(UnmanagedType.I8)] long libOffset, [In, MarshalAs(UnmanagedType.I8)] long cb, [In] int dwLockType);
@@ -820,7 +820,7 @@ namespace HandyControl.Tools.Interop
while (written < cb)
{
var toRead = bufsize;
- if (written + toRead > cb) toRead = (int) (cb - written);
+ if (written + toRead > cb) toRead = (int)(cb - written);
var read = Read(buffer, toRead);
if (read == 0) break;
if (pstm.Write(buffer, read) != read)
@@ -972,5 +972,93 @@ namespace HandyControl.Tools.Interop
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
internal string szCSDVersion;
}
+
+ [Flags]
+ public enum WindowPositionFlags
+ {
+ ///
+ /// If the calling thread and the thread that owns the window are attached to different input queues, the system posts
+ /// the request to the thread that owns the window. This prevents the calling thread from blocking its execution while
+ /// other threads process the request.
+ ///
+ SWP_ASYNCWINDOWPOS = 0x4000,
+
+ ///
+ /// Prevents generation of the WM_SYNCPAINT message.
+ ///
+ SWP_DEFERERASE = 0x2000,
+
+ ///
+ /// Draws a frame (defined in the window's class description) around the window.
+ ///
+ SWP_DRAWFRAME = 0x0020,
+
+ ///
+ /// Applies new frame styles set using the SetWindowLong function. Sends a WM_NCCALCSIZE message to the window, even if
+ /// the window's size is not being changed. If this flag is not specified, WM_NCCALCSIZE is sent only when the window's
+ /// size is being changed.
+ ///
+ SWP_FRAMECHANGED = 0x0020,
+
+ ///
+ /// Hides the window.
+ ///
+ SWP_HIDEWINDOW = 0x0080,
+
+ ///
+ /// Does not activate the window. If this flag is not set, the window is activated and moved to the top of either the
+ /// topmost or non-topmost group (depending on the setting of the hWndInsertAfter parameter).
+ ///
+ SWP_NOACTIVATE = 0x0010,
+
+ ///
+ /// Discards the entire contents of the client area. If this flag is not specified, the valid contents of the client
+ /// area are saved and copied back into the client area after the window is sized or repositioned.
+ ///
+ SWP_NOCOPYBITS = 0x0100,
+
+ ///
+ /// Retains the current position (ignores X and Y parameters).
+ ///
+ SWP_NOMOVE = 0x0002,
+
+ ///
+ /// Does not change the owner window's position in the Z order.
+ ///
+ SWP_NOOWNERZORDER = 0x0200,
+
+ ///
+ /// Does not redraw changes. If this flag is set, no repainting of any kind occurs. This applies to the client area,
+ /// the nonclient area (including the title bar and scroll bars), and any part of the parent window uncovered as a
+ /// result of the window being moved. When this flag is set, the application must explicitly invalidate or redraw any
+ /// parts of the window and parent window that need redrawing.
+ ///
+ SWP_NOREDRAW = 0x0008,
+
+ ///
+ /// Same as the SWP_NOOWNERZORDER flag.
+ ///
+ SWP_NOREPOSITION = 0x0200,
+
+ ///
+ /// Prevents the window from receiving the WM_WINDOWPOSCHANGING message.
+ ///
+ SWP_NOSENDCHANGING = 0x0400,
+
+ ///
+ /// Retains the current size (ignores the cx and cy parameters).
+ ///
+ SWP_NOSIZE = 0x0001,
+
+ ///
+ /// Retains the current Z order (ignores the hWndInsertAfter parameter).
+ ///
+ SWP_NOZORDER = 0x0004,
+
+ ///
+ /// Displays the window.
+ ///
+ SWP_SHOWWINDOW = 0x0040
+ }
}
-}
+}
\ No newline at end of file