diff --git a/BrightSharp/Behaviors/FiterGridTextBoxBehavior.cs b/BrightSharp/Behaviors/FilterDefaultViewTextBoxBehavior.cs similarity index 100% rename from BrightSharp/Behaviors/FiterGridTextBoxBehavior.cs rename to BrightSharp/Behaviors/FilterDefaultViewTextBoxBehavior.cs diff --git a/BrightSharp/Behaviors/MinMaxSize_Logic.cs b/BrightSharp/Behaviors/MinMaxSize_Logic.cs new file mode 100644 index 0000000..55329fd --- /dev/null +++ b/BrightSharp/Behaviors/MinMaxSize_Logic.cs @@ -0,0 +1,78 @@ +using BrightSharp.Interop; +using BrightSharp.Interop.Constants; +using BrightSharp.Interop.Structures; +using System; +using System.Runtime.InteropServices; +using System.Windows; +using System.Windows.Interop; + +namespace BrightSharp.Behaviors +{ + internal class MinMaxSize_Logic + { + private HwndSource hwndSource; + private Window associatedObject; + public MinMaxSize_Logic(Window associatedObject) + { + this.associatedObject = associatedObject; + } + public void OnAttached() + { + this.associatedObject.SourceInitialized += AssociatedObject_SourceInitialized; + } + + private void AssociatedObject_SourceInitialized(object sender, EventArgs e) + { + IntPtr handle = new WindowInteropHelper(this.associatedObject).Handle; + hwndSource = HwndSource.FromHwnd(handle); + hwndSource.AddHook(WindowProc); + } + + public void OnDetaching() + { + this.associatedObject.SourceInitialized -= AssociatedObject_SourceInitialized; + if (hwndSource != null) + { + hwndSource.RemoveHook(WindowProc); + hwndSource.Dispose(); + } + } + + private IntPtr WindowProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) + { + switch (msg) + { + case 0x0024: + WmGetMinMaxInfo(hwnd, lParam); + handled = true; + break; + } + return (IntPtr)0; + } + + private void WmGetMinMaxInfo(IntPtr hwnd, IntPtr lParam) + { + var mmi = (MINMAXINFO)Marshal.PtrToStructure(lParam, typeof(MINMAXINFO)); + + // Adjust the maximized size and position to fit the work area of the correct monitor + IntPtr monitor = NativeMethods.MonitorFromWindow(hwnd, (int)MonitorFromWindowFlags.MONITOR_DEFAULTTONEAREST); + + if (monitor != IntPtr.Zero) + { + var monitorInfo = new MONITORINFO(); + NativeMethods.GetMonitorInfo(monitor, monitorInfo); + RECT rcWorkArea = monitorInfo.rcWork; + RECT rcMonitorArea = monitorInfo.rcMonitor; + mmi.ptMaxPosition.x = Math.Abs(rcWorkArea.Left - rcMonitorArea.Left); + mmi.ptMaxPosition.y = Math.Abs(rcWorkArea.Top - rcMonitorArea.Top); + mmi.ptMaxSize.x = Math.Abs(rcWorkArea.Right - rcWorkArea.Left); + mmi.ptMaxSize.y = Math.Abs(rcWorkArea.Bottom - rcWorkArea.Top); + mmi.ptMinTrackSize.x = (int)associatedObject.MinWidth; + mmi.ptMinTrackSize.y = (int)associatedObject.MinHeight; + } + + Marshal.StructureToPtr(mmi, lParam, true); + } + + } +} diff --git a/BrightSharp/Behaviors/WindowMinMaxSizeBehavior.cs b/BrightSharp/Behaviors/WindowMinMaxSizeBehavior.cs index 3ff9e4d..425282c 100644 --- a/BrightSharp/Behaviors/WindowMinMaxSizeBehavior.cs +++ b/BrightSharp/Behaviors/WindowMinMaxSizeBehavior.cs @@ -1,9 +1,4 @@ -using BrightSharp.Interop; -using BrightSharp.Interop.Constants; -using BrightSharp.Interop.Structures; -using System; -using System.Runtime.InteropServices; -using System.Windows; +using System.Windows; using System.Windows.Interactivity; using System.Windows.Interop; @@ -12,67 +7,19 @@ namespace BrightSharp.Behaviors public class WindowMinMaxSizeBehavior : Behavior { private HwndSource hwndSource; - + private MinMaxSize_Logic logic; protected override void OnAttached() { base.OnAttached(); - - AssociatedObject.SourceInitialized += AssociatedObject_SourceInitialized; - } - - private void AssociatedObject_SourceInitialized(object sender, EventArgs e) - { - IntPtr handle = (new WindowInteropHelper(AssociatedObject)).Handle; - hwndSource = HwndSource.FromHwnd(handle); - hwndSource.AddHook(WindowProc); + logic = new MinMaxSize_Logic(AssociatedObject); + logic.OnAttached(); } + protected override void OnDetaching() { - AssociatedObject.SourceInitialized -= AssociatedObject_SourceInitialized; - if (hwndSource != null) - { - hwndSource.RemoveHook(WindowProc); - hwndSource.Dispose(); - } + logic.OnDetaching(); base.OnDetaching(); } - - private IntPtr WindowProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) - { - switch (msg) - { - case 0x0024: - WmGetMinMaxInfo(hwnd, lParam); - handled = true; - break; - } - return (IntPtr)0; - } - - private void WmGetMinMaxInfo(IntPtr hwnd, IntPtr lParam) - { - var mmi = (MINMAXINFO)Marshal.PtrToStructure(lParam, typeof(MINMAXINFO)); - - // Adjust the maximized size and position to fit the work area of the correct monitor - IntPtr monitor = NativeMethods.MonitorFromWindow(hwnd, (int)MonitorFromWindowFlags.MONITOR_DEFAULTTONEAREST); - - if (monitor != IntPtr.Zero) - { - var monitorInfo = new MONITORINFO(); - NativeMethods.GetMonitorInfo(monitor, monitorInfo); - RECT rcWorkArea = monitorInfo.rcWork; - RECT rcMonitorArea = monitorInfo.rcMonitor; - mmi.ptMaxPosition.x = Math.Abs(rcWorkArea.Left - rcMonitorArea.Left); - mmi.ptMaxPosition.y = Math.Abs(rcWorkArea.Top - rcMonitorArea.Top); - mmi.ptMaxSize.x = Math.Abs(rcWorkArea.Right - rcWorkArea.Left); - mmi.ptMaxSize.y = Math.Abs(rcWorkArea.Bottom - rcWorkArea.Top); - mmi.ptMinTrackSize.x = (int)AssociatedObject.MinWidth; - mmi.ptMinTrackSize.y = (int)AssociatedObject.MinHeight; - } - - Marshal.StructureToPtr(mmi, lParam, true); - } - } } diff --git a/BrightSharp/BrightSharp.csproj b/BrightSharp/BrightSharp.csproj index 7ad816c..6eb908c 100644 --- a/BrightSharp/BrightSharp.csproj +++ b/BrightSharp/BrightSharp.csproj @@ -37,7 +37,9 @@ - + + G:\repositories\Tps.Next\packages\System.Windows.Interactivity.WPF.2.0.20525\lib\net40\System.Windows.Interactivity.dll + @@ -51,8 +53,9 @@ - + + @@ -93,6 +96,7 @@ + Theme.Static.xaml @@ -170,7 +174,9 @@ - + + +