Skip to content

Commit 40c1a09

Browse files
committed
Added "Window Placement" and "Parent Process Id" to the "Information" tab.
1 parent 14c68cb commit 40c1a09

File tree

3 files changed

+40
-4
lines changed

3 files changed

+40
-4
lines changed

WindowTextExtractor/Native/NativeMethods.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ static class NativeMethods
113113
[DllImport("user32.dll")]
114114
public static extern bool GetLayeredWindowAttributes(IntPtr hwnd, out uint crKey, out Byte bAlpha, out uint dwFlags);
115115

116+
[DllImport("user32.dll", SetLastError = true)]
117+
[return: MarshalAs(UnmanagedType.Bool)]
118+
public static extern bool GetWindowPlacement(IntPtr hWnd, ref WINDOWPLACEMENT lpwndpl);
119+
116120
[DllImport("kernel32.dll")]
117121
public static extern bool QueryFullProcessImageName([In] IntPtr hProcess, [In] uint dwFlags, [Out] StringBuilder lpExeName, [In, Out] ref uint lpdwSize);
118122

WindowTextExtractor/Native/NativeTypes.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,23 @@ public enum Priority : int
109109
BelowNormal = 6,
110110
Idle = 4
111111
}
112+
113+
[StructLayout(LayoutKind.Sequential)]
114+
struct WINDOWPLACEMENT
115+
{
116+
public int length;
117+
public int flags;
118+
public ShowWindowCommands showCmd;
119+
public System.Drawing.Point ptMinPosition;
120+
public System.Drawing.Point ptMaxPosition;
121+
public System.Drawing.Rectangle rcNormalPosition;
122+
}
123+
124+
enum ShowWindowCommands : int
125+
{
126+
Hide = 0,
127+
Normal = 1,
128+
Minimized = 2,
129+
Maximized = 3,
130+
}
112131
}

WindowTextExtractor/Utils/WindowUtils.cs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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 placement = GetWindowPlacement(hWnd);
6162
var threadId = NativeMethods.GetWindowThreadProcessId(hWnd, out var processId);
6263
var process = GetProcessByIdSafely(processId);
6364

@@ -83,7 +84,8 @@ public static WindowInformation GetWindowInformation(IntPtr hWnd)
8384
}
8485

8586
windowDetailes.Add("Window Handle", $"0x{hWnd.ToInt64():X}");
86-
windowDetailes.Add("Parent Window Handle", $"0x{hWndParent.ToInt64():X}");
87+
windowDetailes.Add("Parent Window Handle", hWndParent == IntPtr.Zero ? "-" : $"0x{hWndParent.ToInt64():X}");
88+
windowDetailes.Add("Window Placement", placement.showCmd.ToString());
8789
windowDetailes.Add("Window Size", $"{size.Width} x {size.Height}");
8890

8991
try
@@ -175,13 +177,18 @@ public static WindowInformation GetWindowInformation(IntPtr hWnd)
175177
{
176178
}
177179

180+
processDetailes.Add("Process Id", processId.ToString());
178181
try
179182
{
180-
processDetailes.Add("Parent", Path.GetFileName(process.GetParentProcess().MainModule.FileName));
183+
var parentProcess = process.GetParentProcess();
184+
processDetailes.Add("Parent Process Id", parentProcess.Id.ToString());
185+
processDetailes.Add("Parent", Path.GetFileName(parentProcess.MainModule.FileName));
181186
}
182187
catch
183188
{
184189
}
190+
191+
processDetailes.Add("Thread Id", threadId.ToString());
185192

186193
try
187194
{
@@ -191,8 +198,6 @@ public static WindowInformation GetWindowInformation(IntPtr hWnd)
191198
{
192199
}
193200

194-
processDetailes.Add("Process Id", processId.ToString());
195-
processDetailes.Add("Thread Id", threadId.ToString());
196201

197202
try
198203
{
@@ -289,6 +294,14 @@ private static Rect GetWindowSize(IntPtr hWnd)
289294
return size;
290295
}
291296

297+
private static WINDOWPLACEMENT GetWindowPlacement(IntPtr hWnd)
298+
{
299+
var placement = new WINDOWPLACEMENT();
300+
placement.length = Marshal.SizeOf(placement);
301+
NativeMethods.GetWindowPlacement(hWnd, ref placement);
302+
return placement;
303+
}
304+
292305
private static Process GetProcessByIdSafely(int pId)
293306
{
294307
try

0 commit comments

Comments
 (0)