-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Closed
Description
这不是一个HC的bug,但是应该可以在HC里加以规避处理。
现象
在个别人的电脑上会出现一个奇怪的异常:
OverflowException
在 System.Windows.Shell.WindowChromeWorker._HandleNCHitTest(WM uMsg, IntPtr wParam, IntPtr lParam, Boolean& handled)
在 System.Windows.Shell.WindowChromeWorker._WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
在 System.Windows.Interop.HwndSource.PublicHooksFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
在 MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
在 MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
在 System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
在 System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
相关信息
在StackOverflow上找到一个相关的帖子:
https://stackoverflow.com/questions/33287542/what-would-cause-wm-nchittest-lparam-to-overflow-a-32-bit-integer
里面有人贴了一个一个网址:
https://developercommunity.visualstudio.com/t/overflow-exception-in-windowchrome/167357
提到的解决方法:
protected override void OnSourceInitialized( EventArgs e )
{
base.OnSourceInitialized( e );
( (HwndSource)PresentationSource.FromVisual( this ) ).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
try
{
lParam.ToInt32();
}
catch ( OverflowException )
{
handled = true;
}
}
return IntPtr.Zero;
}
其它相关链接:
- WindowChrome System.OverflowException:“Arithmetic operation resulted in an overflow.” dotnet/wpf#1269
- https://stackoverflow.com/questions/50282355/why-does-my-wpf-application-crash-when-i-bump-my-mousewheel/50282356#50282356
- https://github.com/ControlzEx/ControlzEx/blob/45ddf61998019e9eae74fe88acae474a4eec038b/src/ControlzEx/Microsoft.Windows.Shell/Standard/Utilities.cs#L132
NaBian
Metadata
Metadata
Assignees
Labels
No labels