|
@@ -768,6 +768,15 @@ namespace fis.Win
|
|
|
[DllImport("user32.dll", SetLastError = true)]
|
|
|
private static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);
|
|
|
|
|
|
+ [DllImport("user32.dll")]
|
|
|
+ private static extern bool IsIconic(IntPtr hWnd);
|
|
|
+
|
|
|
+ [DllImport("user32.dll")]
|
|
|
+ private static extern bool IsZoomed(IntPtr hWnd);
|
|
|
+
|
|
|
+ [DllImport("user32.dll")]
|
|
|
+ private static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
|
|
|
+
|
|
|
private static readonly Dictionary<string, IntPtr> _windowHandles = new Dictionary<string, IntPtr>();
|
|
|
|
|
|
private static IntPtr _dragingWindowHandle;
|
|
@@ -779,16 +788,28 @@ namespace fis.Win
|
|
|
private static HookProc? _hookProc = null;
|
|
|
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// Register one window into the draging process manager.
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="windowName">The name of the window.</param>
|
|
|
+ /// <param name="windowHandle">The handle of the window, can be acquired from window.PlatormImpl.Handle.Handle</param>
|
|
|
public static void RegisterWindow(string windowName, IntPtr windowHandle)
|
|
|
{
|
|
|
_windowHandles.Add(windowName, windowHandle);
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// Unregister the window from the draging process manager.
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="windowName">The window name.</param>
|
|
|
public static void UnRegisterWindow(string windowName)
|
|
|
{
|
|
|
_windowHandles.Remove(windowName);
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// Start the mouse monitor, remember stop it when the main window closed.
|
|
|
+ /// </summary>
|
|
|
public static void StartMouseMonitor()
|
|
|
{
|
|
|
_hookProc = OnMouseHookProc;
|
|
@@ -801,6 +822,9 @@ namespace fis.Win
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// Stop the mouse monitor.
|
|
|
+ /// </summary>
|
|
|
public static void StopMouseMonitor()
|
|
|
{
|
|
|
if (_mouseHookHandle != IntPtr.Zero)
|
|
@@ -855,6 +879,42 @@ namespace fis.Win
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ //Minimize the window
|
|
|
+ public static void MinimizeWindow(string windowName)
|
|
|
+ {
|
|
|
+ if (_windowHandles.TryGetValue(windowName, out var windowHandle))
|
|
|
+ {
|
|
|
+ //SW_MINIMIZE = 6
|
|
|
+ //SW_SHOWMINIMIZED = 2
|
|
|
+ //SW_SHOWMINNOACTIVE = 7
|
|
|
+ ShowWindow(windowHandle, 6);
|
|
|
+ EndWindowDrag(windowName);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //Maximize the window
|
|
|
+ public static void MaximizeWindow(string windowName)
|
|
|
+ {
|
|
|
+ if (_windowHandles.TryGetValue(windowName, out var windowHandle))
|
|
|
+ {
|
|
|
+ //SW_MAXIMIZE = 3
|
|
|
+ ShowWindow(windowHandle, 3);
|
|
|
+ EndWindowDrag(windowName);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //Restore the window
|
|
|
+ public static void RestoreWindow(string windowName)
|
|
|
+ {
|
|
|
+ if (_windowHandles.TryGetValue(windowName, out var windowHandle))
|
|
|
+ {
|
|
|
+ //SW_RESTORE = 9
|
|
|
+ ShowWindow(windowHandle, 9);
|
|
|
+ EndWindowDrag(windowName);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private static int OnMouseHookProc(int nCode, int wParam, IntPtr lParam)
|
|
|
{
|
|
|
if (_dragingWindowHandle != IntPtr.Zero)
|
|
@@ -862,13 +922,38 @@ namespace fis.Win
|
|
|
if (wParam == (int)MessageType.WM_MOUSEMOVE)
|
|
|
{
|
|
|
var mouseData = Marshal.PtrToStructure<MOUSEHOOKSTRUCT>(lParam);
|
|
|
- if (GetWindowRect(_dragingWindowHandle, out var rect))
|
|
|
+ if(IsZoomed(_dragingWindowHandle))
|
|
|
+ {
|
|
|
+ //窗体最大化的时候拖动还原窗口
|
|
|
+ if (GetWindowRect(_dragingWindowHandle, out var rect))
|
|
|
+ {
|
|
|
+ var width = rect.Right - rect.Left;
|
|
|
+ var height = rect.Bottom - rect.Top;
|
|
|
+ var offsetXRatio = (double)(mouseData.pt.X - rect.Left) / width;
|
|
|
+ //SW_RESTORE = 9
|
|
|
+ ShowWindow(_dragingWindowHandle, 9);
|
|
|
+ if (GetWindowRect(_dragingWindowHandle, out rect))
|
|
|
+ {
|
|
|
+ width = rect.Right - rect.Left;
|
|
|
+ height = rect.Bottom - rect.Top;
|
|
|
+ _dragOffset.X = (int)(width * offsetXRatio);
|
|
|
+ if (MoveWindow(_dragingWindowHandle, mouseData.pt.X - _dragOffset.X, mouseData.pt.Y - _dragOffset.Y, width, height, true))
|
|
|
+ {
|
|
|
+ //
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
{
|
|
|
- var width = rect.Right - rect.Left;
|
|
|
- var height = rect.Bottom - rect.Top;
|
|
|
- if (MoveWindow(_dragingWindowHandle, mouseData.pt.X - _dragOffset.X, mouseData.pt.Y - _dragOffset.Y, width, height, true))
|
|
|
+ if (GetWindowRect(_dragingWindowHandle, out var rect))
|
|
|
{
|
|
|
- //
|
|
|
+ var width = rect.Right - rect.Left;
|
|
|
+ var height = rect.Bottom - rect.Top;
|
|
|
+ if (MoveWindow(_dragingWindowHandle, mouseData.pt.X - _dragOffset.X, mouseData.pt.Y - _dragOffset.Y, width, height, true))
|
|
|
+ {
|
|
|
+ //
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|