Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions src/Wpf.Ui/Controls/TitleBar/TitleBarButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
3 changes: 3 additions & 0 deletions src/Wpf.Ui/Interop/User32.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down