mirror of
https://github.com/ckaczor/Common.Wpf.git
synced 2026-01-14 01:25:37 -05:00
Clean up other window checking for snapping windows
This commit is contained in:
@@ -182,6 +182,7 @@
|
||||
<Compile Include="Toolbar\SplitButton\SplitButton.cs" />
|
||||
<Compile Include="Windows\ControlBox.cs" />
|
||||
<Compile Include="Windows\SnappingWindow.cs" />
|
||||
<Compile Include="Windows\WindowInformation.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Page Include="HtmlLabelControl\HtmlLabel.xaml">
|
||||
|
||||
@@ -17,6 +17,7 @@ namespace Common.Wpf.Windows
|
||||
|
||||
private HwndSource _hwndSource;
|
||||
private Structures.WindowPosition _lastWindowPosition;
|
||||
private List<WindowInformation> _otherWindows;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -37,7 +38,7 @@ namespace Common.Wpf.Windows
|
||||
get { return 20; }
|
||||
}
|
||||
|
||||
protected virtual List<Rect> OtherWindows
|
||||
protected virtual List<WindowInformation> 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);
|
||||
|
||||
30
Windows/WindowInformation.cs
Normal file
30
Windows/WindowInformation.cs
Normal file
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user