Skip to content

Commit

Permalink
Wpf: Fix crash with certain mouse drivers
Browse files Browse the repository at this point in the history
  • Loading branch information
cwensley committed Apr 24, 2024
1 parent 008fb16 commit fb78b41
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/Eto.Wpf/Forms/WpfWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,27 @@ private void Control_SourceInitialized(object sender, EventArgs e)
SetLocation(initialLocation.Value);
initialLocation = null;
}

((swin.HwndSource)sw.PresentationSource.FromVisual(Control)).AddHook(HookProc);
}

private IntPtr HookProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
if (msg == 0x0084 /*WM_NCHITTEST*/ )
{
// This prevents a crash in WindowChromeWorker._HandleNCHitTest with some mouse drivers
// See https://github.com/dotnet/wpf/issues/6777 for more information
// This was fixed in .NET 8 but this is here to avoid the crash in .NET Framework 4.8 and .NET 7.
try
{
lParam.ToInt32();
}
catch (OverflowException)
{
handled = true;
}
}
return IntPtr.Zero;
}

private void Control_Loaded(object sender, sw.RoutedEventArgs e)
Expand Down

0 comments on commit fb78b41

Please sign in to comment.