Browse Source

Restore window when window is max and is begin draging.

Justin 2 years ago
parent
commit
645af41022
1 changed files with 40 additions and 5 deletions
  1. 40 5
      fis/Win/WindowDragingHelper.cs

+ 40 - 5
fis/Win/WindowDragingHelper.cs

@@ -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;
@@ -855,6 +864,7 @@ namespace fis.Win
             }
         }
 
+
         private static int OnMouseHookProc(int nCode, int wParam, IntPtr lParam)
         {
             if (_dragingWindowHandle != IntPtr.Zero)
@@ -862,13 +872,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))
+                            {
+                                //
+                            }
                         }
                     }
                 }