diff --git a/windows/TweetDuck.Video/FormPlayer.cs b/windows/TweetDuck.Video/FormPlayer.cs index 39af1ec4..6e77cd75 100644 --- a/windows/TweetDuck.Video/FormPlayer.cs +++ b/windows/TweetDuck.Video/FormPlayer.cs @@ -237,7 +237,7 @@ private void timerSync_Tick(object? sender, EventArgs e) { int maxWidth = Math.Min(DpiScaled(media.imageSourceWidth), ownerWidth * 3 / 4); int maxHeight = Math.Min(DpiScaled(media.imageSourceHeight), ownerHeight * 3 / 4); - bool isCursorInside = ClientRectangle.Contains(PointToClient(Cursor.Position)); + bool isCursorInside = ClientRectangle.Contains(PointToClient(Cursor.Position)) && Handle == NativeMethods.GetFormHandleAt(Cursor.Position); Size newSize = new Size(Math.Max(minWidth + 2, maxWidth), Math.Max(minHeight + 2, maxHeight)); Point newLocation = new Point(ownerLeft + (ownerWidth - newSize.Width) / 2, ownerTop + (ownerHeight - newSize.Height + SystemInformation.CaptionHeight) / 2); diff --git a/windows/TweetDuck.Video/NativeMethods.cs b/windows/TweetDuck.Video/NativeMethods.cs index c0edc887..8f46a2e3 100644 --- a/windows/TweetDuck.Video/NativeMethods.cs +++ b/windows/TweetDuck.Video/NativeMethods.cs @@ -1,11 +1,13 @@ #nullable enable using System; using System.Diagnostics.CodeAnalysis; +using System.Drawing; using System.Runtime.InteropServices; namespace TweetDuck.Video { [SuppressMessage("ReSharper", "InconsistentNaming")] static class NativeMethods { + private const int GA_ROOT = 2; private const int GWL_HWNDPARENT = -8; [DllImport("user32.dll")] @@ -24,6 +26,12 @@ static class NativeMethods { [DllImport("user32.dll")] public static extern IntPtr GetForegroundWindow(); + + [DllImport("user32.dll")] + private static extern IntPtr WindowFromPoint(Point point); + + [DllImport("user32.dll")] + private static extern IntPtr GetAncestor(IntPtr hwnd, int flags); [DllImport("user32.dll")] public static extern bool SetProcessDPIAware(); @@ -49,5 +57,10 @@ public static void SetWindowOwner(IntPtr child, IntPtr owner) { * ...so technically, this is following the documentation to the word. */ } + + public static IntPtr GetFormHandleAt(Point point) { + IntPtr window = WindowFromPoint(point); + return window == IntPtr.Zero ? IntPtr.Zero : GetAncestor(window, GA_ROOT); + } } }