diff --git a/Common.Wpf.csproj b/Common.Wpf.csproj
index 67e8d2d..c8637ef 100644
--- a/Common.Wpf.csproj
+++ b/Common.Wpf.csproj
@@ -182,6 +182,7 @@
+
diff --git a/Windows/SnappingWindow.cs b/Windows/SnappingWindow.cs
index 3956d93..becf5b4 100644
--- a/Windows/SnappingWindow.cs
+++ b/Windows/SnappingWindow.cs
@@ -17,6 +17,7 @@ namespace Common.Wpf.Windows
private HwndSource _hwndSource;
private Structures.WindowPosition _lastWindowPosition;
+ private List _otherWindows;
#endregion
@@ -37,7 +38,7 @@ namespace Common.Wpf.Windows
get { return 20; }
}
- protected virtual List OtherWindows
+ protected virtual List OtherWindows
{
get { return null; }
}
@@ -88,11 +89,14 @@ namespace Common.Wpf.Windows
#region Window procedure
- private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
+ protected virtual IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
if (msg == (int) Constants.WindowMessage.WindowPositionChanging)
return OnWindowPositionChanging(lParam, ref handled);
+ if (msg == (int) Constants.WindowMessage.EnterSizeMove)
+ _otherWindows = OtherWindows;
+
return IntPtr.Zero;
}
@@ -197,15 +201,15 @@ namespace Common.Wpf.Windows
}
}
- var otherWindows = OtherWindows;
+ var otherWindows = _otherWindows;
if (otherWindows != null && otherWindows.Count > 0)
{
// Loop over all other windows looking to see if we should stick
- foreach (Rect otherWindow in otherWindows)
+ foreach (var otherWindow in otherWindows)
{
// Get a rectangle with the bounds of the other window
- var otherWindowRect = new Rectangle(Convert.ToInt32(otherWindow.Left), Convert.ToInt32(otherWindow.Top), Convert.ToInt32(otherWindow.Width), Convert.ToInt32(otherWindow.Height));
+ var otherWindowRect = otherWindow.Location;
// Check the current window left against the other window right
var otherWindowSnapBorder = new Rectangle(otherWindowRect.Right, otherWindowRect.Top, snapDistance, otherWindowRect.Height);
diff --git a/Windows/WindowInformation.cs b/Windows/WindowInformation.cs
new file mode 100644
index 0000000..af0b958
--- /dev/null
+++ b/Windows/WindowInformation.cs
@@ -0,0 +1,30 @@
+using Common.Native;
+using System;
+using System.Drawing;
+
+namespace Common.Wpf.Windows
+{
+ public class WindowInformation
+ {
+ public IntPtr Handle { get; private set; }
+ public Rectangle Location { get; private set; }
+
+ public WindowInformation(IntPtr handle)
+ {
+ Handle = handle;
+
+ var windowPlacement = new Structures.WindowPlacement();
+ Functions.User32.GetWindowPlacement(Handle, ref windowPlacement);
+
+ var normalPosition = windowPlacement.NormalPosition;
+
+ Location = new Rectangle(normalPosition.X, normalPosition.Y, normalPosition.Width, normalPosition.Height);
+ }
+
+ public WindowInformation(IntPtr handle, Rectangle location)
+ {
+ Handle = handle;
+ Location = location;
+ }
+ }
+}