Skip to content

Commit acd9e90

Browse files
committed
More correct window image (screenshot) without frame bounds
1 parent 5b2013a commit acd9e90

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

WindowTextExtractor/Utils/WindowUtils.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ public static WindowInformation GetWindowInformation(IntPtr handle, Point cursor
302302

303303
public static Bitmap CaptureWindow(IntPtr handle, bool captureCursor = false)
304304
{
305-
User32.GetWindowRect(handle, out var rectangle);
305+
var rectangle = GetWindowRectWithoutMargins(handle);
306306
var posX = rectangle.Left;
307307
var posY = rectangle.Top;
308308
var width = rectangle.Width;
@@ -534,6 +534,21 @@ private static Color GetColorUnderCursor(Point cursorPosition)
534534
return color;
535535
}
536536

537+
private static Rect GetWindowRectWithoutMargins(IntPtr hWnd)
538+
{
539+
Rect size;
540+
if (Environment.OSVersion.Version.Major < 6)
541+
{
542+
User32.GetWindowRect(hWnd, out size);
543+
}
544+
else if (Dwmapi.DwmGetWindowAttribute(hWnd, Constants.DWMWA_EXTENDED_FRAME_BOUNDS, out size, Marshal.SizeOf(typeof(Rect))) != 0)
545+
{
546+
User32.GetWindowRect(hWnd, out size);
547+
}
548+
return size;
549+
}
550+
551+
537552
private class WmiProcessInfo
538553
{
539554
public string CommandLine { get; set; }

0 commit comments

Comments
 (0)