diff --git a/src/Wpf.Ui/Controls/TitleBar/TitleBarButton.cs b/src/Wpf.Ui/Controls/TitleBar/TitleBarButton.cs index 83f8ad744..bc7f7dccb 100644 --- a/src/Wpf.Ui/Controls/TitleBar/TitleBarButton.cs +++ b/src/Wpf.Ui/Controls/TitleBar/TitleBarButton.cs @@ -232,4 +232,39 @@ protected void OnButtonTypeChanged(DependencyPropertyChangedEventArgs e) ), }; } + + PresentationSource presentationSource = null; + + protected bool IsMouseOverElement(nint lParam) + { + System.Drawing.Point winPoint; + bool gotCursorPos = User32.GetCursorPos(out winPoint); + + if (!gotCursorPos) + { + int fallbackX = unchecked((short)((long)lParam & 0xFFFF)); + int fallbackY = unchecked((short)(((long)lParam >> 16) & 0xFFFF)); + winPoint = new System.Drawing.Point(fallbackX, fallbackY); + } + + var screenPoint = new System.Windows.Point(winPoint.X, winPoint.Y); + + presentationSource ??= PresentationSource.FromVisual(this); + + if (presentationSource?.CompositionTarget != null) + { + screenPoint = presentationSource.CompositionTarget.TransformFromDevice.Transform(screenPoint); + } + + var localPoint = this.PointFromScreen(screenPoint); + + var hitTestRect = + new System.Windows.Rect( + 0, + 0, + this.ActualWidth, + this.ActualHeight); + + return hitTestRect.Contains(localPoint); + } } diff --git a/src/Wpf.Ui/Interop/User32.cs b/src/Wpf.Ui/Interop/User32.cs index 43e39563d..ffc967ed6 100644 --- a/src/Wpf.Ui/Interop/User32.cs +++ b/src/Wpf.Ui/Interop/User32.cs @@ -1450,6 +1450,9 @@ [In] IntPtr lParam [DllImport(Libraries.User32, SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool GetCursorPos([Out] out WinDef.POINT lpPoint); + [DllImport(Libraries.User32, SetLastError = true)] + public static extern bool GetCursorPos(out System.Drawing.Point lpPoint); + [DllImport(Libraries.User32)] public static extern bool UnionRect(out WinDef.RECT rcDst, ref WinDef.RECT rc1, ref WinDef.RECT rc2);