I'm trying to reliably detect when a Form is currently docked. My current code works, but not when scaling is different than 100%, predictably.
I'm trying to find a function that will return the working area coordinates that will match what GetExtendedFrameBounds (PInvoke: DwmGetWindowAttribute with DWMWA_EXTENDED_FRAME_BOUNDS) gives me to work with, which I'm using to detect docking.
public static bool IsWindowDocked(Form form, int numSides = 3)
{
var workArea = Screen.GetWorkingArea(form);
var winRect = PInvoke.GetExtendedFrameBounds(form.Handle);
var score = (winRect.Left == workArea.Left ? 1 : 0) +
(winRect.Top == workArea.Top ? 1 : 0) +
(winRect.Right == workArea.Right ? 1 : 0) +
(winRect.Bottom == workArea.Bottom ? 1 : 0);
return (score >= numSides);
}
Current result will detect docking on 100% scaling, but not other display scaling values!