Skip to content

Commit 2898b06

Browse files
committed
Added "Window Client Size" and "Window Extended Frame Bounds" to the "Information" tab
1 parent 6ac43b1 commit 2898b06

File tree

3 files changed

+59
-4
lines changed

3 files changed

+59
-4
lines changed

WindowTextExtractor/Native/NativeConstants.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,7 @@ static class NativeConstants
2626
public const int GCL_WNDPROC = -24;
2727
public const int DWL_DLGPROC = 4;
2828
public const int DWL_USER = 8;
29+
30+
public const int DWMWA_EXTENDED_FRAME_BOUNDS = 9;
2931
}
3032
}

WindowTextExtractor/Native/NativeMethods.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ static class NativeMethods
8282
[return: MarshalAs(UnmanagedType.Bool)]
8383
public static extern bool GetWindowRect(IntPtr hWnd, out Rect lpRect);
8484

85+
[DllImport("user32.dll")]
86+
[return: MarshalAs(UnmanagedType.Bool)]
87+
public static extern bool GetClientRect(IntPtr handle, out Rect lpRect);
88+
8589
[DllImport("user32.dll", CharSet = CharSet.Auto)]
8690
public static extern int GetWindowText(IntPtr hWnd, StringBuilder title, int size);
8791

@@ -128,5 +132,8 @@ static class NativeMethods
128132

129133
[DllImport("kernel32.dll")]
130134
public static extern IntPtr OpenProcess(int dwDesiredAccess, bool bInheritHandle, int dwProcessId);
135+
136+
[DllImport("dwmapi.dll")]
137+
public static extern int DwmGetWindowAttribute(IntPtr hwnd, int dwAttribute, out Rect pvAttribute, int cbAttribute);
131138
}
132139
}

WindowTextExtractor/Utils/WindowUtils.cs

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.IO;
35
using System.Text;
46
using System.Drawing;
57
using System.Drawing.Imaging;
68
using System.Diagnostics;
79
using System.Runtime.InteropServices;
810
using System.Management;
9-
using System.Linq;
10-
using System.IO;
1111
using mshtml;
1212
using WindowTextExtractor.Native;
1313
using WindowTextExtractor.Extensions;
@@ -58,6 +58,7 @@ public static WindowInformation GetWindowInformation(IntPtr hWnd)
5858
var realWindowClass = RealGetWindowClass(hWnd);
5959
var hWndParent = NativeMethods.GetParent(hWnd);
6060
var size = GetWindowSize(hWnd);
61+
var clientSize = GetWindowClientSize(hWnd);
6162
var placement = GetWindowPlacement(hWnd);
6263
var threadId = NativeMethods.GetWindowThreadProcessId(hWnd, out var processId);
6364
var process = GetProcessByIdSafely(processId);
@@ -86,8 +87,18 @@ public static WindowInformation GetWindowInformation(IntPtr hWnd)
8687
windowDetailes.Add("Window Handle", $"0x{hWnd.ToInt64():X}");
8788
windowDetailes.Add("Parent Window Handle", hWndParent == IntPtr.Zero ? "-" : $"0x{hWndParent.ToInt64():X}");
8889
windowDetailes.Add("Window Placement", placement.showCmd.ToString());
89-
windowDetailes.Add("Window Size", $"{size.Width} x {size.Height}");
90-
90+
windowDetailes.Add("Window Size", $"{size.Width}x{size.Height}");
91+
windowDetailes.Add("Window Client Size", $"{clientSize.Width}x{clientSize.Height}");
92+
93+
try
94+
{
95+
var bounds = GetFrameBounds(hWnd);
96+
windowDetailes.Add("Window Extended Frame Bounds", $"{bounds.Top} {bounds.Right} {bounds.Bottom} {bounds.Left}");
97+
}
98+
catch
99+
{
100+
}
101+
91102
try
92103
{
93104
windowDetailes.Add("Instance", $"0x{process.Modules[0].BaseAddress.ToInt64():X}");
@@ -294,6 +305,13 @@ private static Rect GetWindowSize(IntPtr hWnd)
294305
return size;
295306
}
296307

308+
private static Rect GetWindowClientSize(IntPtr hWnd)
309+
{
310+
Rect size;
311+
NativeMethods.GetClientRect(hWnd, out size);
312+
return size;
313+
}
314+
297315
private static WINDOWPLACEMENT GetWindowPlacement(IntPtr hWnd)
298316
{
299317
var placement = new WINDOWPLACEMENT();
@@ -302,6 +320,34 @@ private static WINDOWPLACEMENT GetWindowPlacement(IntPtr hWnd)
302320
return placement;
303321
}
304322

323+
private static Rect GetSizeWithFrameBounds(IntPtr hWnd)
324+
{
325+
Rect size;
326+
if (Environment.OSVersion.Version.Major < 6)
327+
{
328+
NativeMethods.GetWindowRect(hWnd, out size);
329+
}
330+
else if (NativeMethods.DwmGetWindowAttribute(hWnd, NativeConstants.DWMWA_EXTENDED_FRAME_BOUNDS, out size, Marshal.SizeOf(typeof(Rect))) != 0)
331+
{
332+
NativeMethods.GetWindowRect(hWnd, out size);
333+
}
334+
return size;
335+
}
336+
337+
private static Rect GetFrameBounds(IntPtr hWnd)
338+
{
339+
var withMargin = GetSizeWithFrameBounds(hWnd);
340+
var size = GetWindowSize(hWnd);
341+
return new Rect
342+
{
343+
Left = withMargin.Left - size.Left,
344+
Top = withMargin.Top - size.Top,
345+
Right = size.Right - withMargin.Right,
346+
Bottom = size.Bottom - withMargin.Bottom
347+
};
348+
}
349+
350+
305351
private static Process GetProcessByIdSafely(int pId)
306352
{
307353
try

0 commit comments

Comments
 (0)