Skip to content

Commit

Permalink
check for RootVisual in GlowWindowBehavior
Browse files Browse the repository at this point in the history
  • Loading branch information
punker76 committed Aug 26, 2017
1 parent d47e2f0 commit c900c5b
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class GlowWindowBehavior : Behavior<Window>
private GlowWindow left, right, top, bottom;
private DispatcherTimer makeGlowVisibleTimer;
private IntPtr handle;
private HwndSource hwndSource;

private bool IsGlowDisabled
{
Expand All @@ -34,16 +35,16 @@ private bool IsWindowTransitionsEnabled
return metroWindow != null && metroWindow.WindowTransitionsEnabled;
}
}

protected override void OnAttached()
{
base.OnAttached();

this.AssociatedObject.SourceInitialized += (o, args) =>
{
this.handle = new WindowInteropHelper(this.AssociatedObject).Handle;
var hwndSource = HwndSource.FromHwnd(this.handle);
hwndSource?.AddHook(this.AssociatedObjectWindowProc);
this.hwndSource = HwndSource.FromHwnd(this.handle);
this.hwndSource?.AddHook(this.AssociatedObjectWindowProc);
};
this.AssociatedObject.Loaded += this.AssociatedObjectOnLoaded;
this.AssociatedObject.Unloaded += this.AssociatedObjectUnloaded;
Expand Down Expand Up @@ -158,6 +159,11 @@ private void AssociatedObjectOnLoaded(object sender, RoutedEventArgs routedEvent

private IntPtr AssociatedObjectWindowProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
if (hwndSource?.RootVisual == null)
{
return IntPtr.Zero;
}

switch ((WM)msg)
{
case WM.WINDOWPOSCHANGED:
Expand Down

0 comments on commit c900c5b

Please sign in to comment.