Skip to content

Commit

Permalink
Fixes #159 by adding an additional fix to WindowSizing (could also be…
Browse files Browse the repository at this point in the history
… a fix for #80)
  • Loading branch information
batzen committed Aug 25, 2015
1 parent b99ba02 commit 76077ae
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 35 deletions.
91 changes: 59 additions & 32 deletions Fluent/Internal/WindowSizing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class WindowSizing
{
private readonly RibbonWindow window;
private IntPtr windowHwnd;
private bool fixingNastyWindowChromeBug;
private bool fixingWindowChromeBug;

/// <summary>
/// Creates a new instance and binds it to <paramref name="window"/>
Expand All @@ -37,27 +37,27 @@ public void WindowInitialized()
this.windowHwnd = hwndSource.Handle;
hwndSource.AddHook(this.HwndHook);

this.window.Dispatcher.BeginInvoke((Action)(this.FixNastyWindowChromeBug));
this.window.Dispatcher.BeginInvoke((Action)(this.FixWindowChromeBug));
}
}

private void HandleWindowStateChanged(object sender, EventArgs e)
{
this.window.Dispatcher.BeginInvoke((Action)(this.FixNastyWindowChromeBug));
this.window.Dispatcher.BeginInvoke((Action)(this.FixWindowChromeBug));
}

private void FixNastyWindowChromeBug()
private void FixWindowChromeBug()
{
if (this.fixingNastyWindowChromeBug)
if (this.fixingWindowChromeBug)
{
return;
}

this.fixingNastyWindowChromeBug = true;
this.fixingWindowChromeBug = true;

if (this.window.WindowState == WindowState.Maximized)
{
this.FixNastyWindowChromeBugForMaximizedWindow();
this.FixWindowChromeBugForMaximizedWindow();
}
else if (this.window.SizeToContent == SizeToContent.WidthAndHeight)
{
Expand All @@ -66,48 +66,75 @@ private void FixNastyWindowChromeBug()
this.window.SizeToContent = SizeToContent.Manual;
}

this.fixingNastyWindowChromeBug = false;
this.fixingWindowChromeBug = false;
}

private void FixNastyWindowChromeBugForMaximizedWindow()
private IntPtr HwndHook(IntPtr hWnd, int message, IntPtr wParam, IntPtr lParam, ref bool handled)
{
var mmi = this.GetMinMaxInfo(this.windowHwnd, new MINMAXINFO());
if (NativeMethods.IsDwmEnabled())
var returnval = IntPtr.Zero;

switch (message)
{
UnsafeNativeMethods.MoveWindow(this.windowHwnd, mmi.ptMaxPosition.X + 10, mmi.ptMaxPosition.Y, mmi.ptMaxSize.X, mmi.ptMaxSize.Y, true);
UnsafeNativeMethods.MoveWindow(this.windowHwnd, mmi.ptMaxPosition.X, mmi.ptMaxPosition.Y, mmi.ptMaxSize.X, mmi.ptMaxSize.Y, true);
case Constants.WM_STYLECHANGED:
this.FixWindowChromeBugForFreezedMaximizedWindow();
break;

case Constants.WM_GETMINMAXINFO:
this.FixMinMaxInfo(hWnd, lParam, out handled);
break;
}
else

return returnval;
}

private WINDOWPLACEMENT GetWindowPlacement()
{
WINDOWPLACEMENT windowPlacement;
UnsafeNativeMethods.GetWindowPlacement(this.windowHwnd, out windowPlacement);
return windowPlacement;
}

#region Fixes

private void FixWindowChromeBugForFreezedMaximizedWindow()
{
if (this.GetWindowPlacement().showCmd == 3)
{
UnsafeNativeMethods.MoveWindow(this.windowHwnd, mmi.ptMaxPosition.X, mmi.ptMaxPosition.Y + 1, mmi.ptMaxSize.X, mmi.ptMaxSize.Y, true);
UnsafeNativeMethods.MoveWindow(this.windowHwnd, mmi.ptMaxPosition.X, mmi.ptMaxPosition.Y, mmi.ptMaxSize.X, mmi.ptMaxSize.Y, true);
this.FixWindowChromeBugForMaximizedWindow();
}
}

private IntPtr HwndHook(IntPtr hWnd, int message, IntPtr wParam, IntPtr lParam, ref bool handled)
private void FixMinMaxInfo(IntPtr hWnd, IntPtr lParam, out bool handled)
{
var returnval = IntPtr.Zero;

switch (message)
if (this.GetWindowPlacement().showCmd == 3)
{
case Constants.WM_GETMINMAXINFO:
/* http://blogs.msdn.com/b/llobo/archive/2006/08/01/maximizing-window-_2800_with-windowstyle_3d00_none_2900_-considering-taskbar.aspx */
this.WmGetMinMaxInfo(hWnd, lParam);

WINDOWPLACEMENT windowPlacement;
UnsafeNativeMethods.GetWindowPlacement(this.windowHwnd, out windowPlacement);
handled = true;
return;
}

if (windowPlacement.showCmd == 3)
{
/* http://blogs.msdn.com/b/llobo/archive/2006/08/01/maximizing-window-_2800_with-windowstyle_3d00_none_2900_-considering-taskbar.aspx */
this.WmGetMinMaxInfo(hWnd, lParam);
handled = false;
}

handled = true;
}
break;
private void FixWindowChromeBugForMaximizedWindow()
{
var mmi = this.GetMinMaxInfo(this.windowHwnd, new MINMAXINFO());
if (NativeMethods.IsDwmEnabled())
{
UnsafeNativeMethods.MoveWindow(this.windowHwnd, mmi.ptMaxPosition.X + 10, mmi.ptMaxPosition.Y, mmi.ptMaxSize.X, mmi.ptMaxSize.Y, true);
UnsafeNativeMethods.MoveWindow(this.windowHwnd, mmi.ptMaxPosition.X, mmi.ptMaxPosition.Y, mmi.ptMaxSize.X, mmi.ptMaxSize.Y, true);
}
else
{
UnsafeNativeMethods.MoveWindow(this.windowHwnd, mmi.ptMaxPosition.X, mmi.ptMaxPosition.Y + 1, mmi.ptMaxSize.X, mmi.ptMaxSize.Y, true);
UnsafeNativeMethods.MoveWindow(this.windowHwnd, mmi.ptMaxPosition.X, mmi.ptMaxPosition.Y, mmi.ptMaxSize.X, mmi.ptMaxSize.Y, true);
}

return returnval;
}

#endregion

#region WindowSize

private bool IgnoreTaskBar()
Expand Down
11 changes: 8 additions & 3 deletions Fluent/Metro/Native/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,22 @@
{
#pragma warning disable 1591
#pragma warning disable 3003
public static class Constants
internal static class Constants
{
public const int MONITOR_DEFAULTTONEAREST = 0x00000002;

public const int WM_NCCALCSIZE = 0x83;
public const int WM_NCPAINT = 0x85;
public const int WM_NCACTIVATE = 0x86;
public const int WM_GETMINMAXINFO = 0x24;
public const int WM_STYLECHANGED = 0x7d;
public const int WM_CREATE = 0x0001;
public const long WS_MAXIMIZE = 0x01000000;
public const int GCLP_HBRBACKGROUND = -0x0A;
public const int WM_NCHITTEST = 0x84;

public const long WS_MAXIMIZE = 0x01000000;

public const int GCLP_HBRBACKGROUND = -0x0A;

public const int HTLEFT = 0x0A;
public const int HTRIGHT = 0x0B;
public const int HTTOP = 0x0C;
Expand Down

0 comments on commit 76077ae

Please sign in to comment.