@@ -27,10 +27,14 @@ void PrintWindowHeadings(const PrintWindowOptions& print)
27
27
_tprintf (_T (" %-10s" ), _T (" HANDLE" ));
28
28
break ;
29
29
30
- case _T (' a ' ):
30
+ case _T (' P ' ):
31
31
_tprintf (_T (" %-10s" ), _T (" PARENT" ));
32
32
break ;
33
33
34
+ case _T (' R' ):
35
+ _tprintf (_T (" %-10s" ), _T (" ROOT" ));
36
+ break ;
37
+
34
38
case _T (' t' ):
35
39
_tprintf (_T (" %s" ), _T (" TITLE" ));
36
40
break ;
@@ -69,10 +73,14 @@ void PrintWindow(HWND hWnd, const PrintWindowOptions& print)
69
73
_tprintf (_T (" 0x%08" ) _T (PRIXPTR), reinterpret_cast <uintptr_t >(hWnd));
70
74
break ;
71
75
72
- case _T (' a ' ):
76
+ case _T (' P ' ):
73
77
_tprintf (_T (" 0x%08" ) _T (PRIXPTR), reinterpret_cast <uintptr_t >(GetParent (hWnd)));
74
78
break ;
75
79
80
+ case _T (' R' ):
81
+ _tprintf (_T (" 0x%08" ) _T (PRIXPTR), reinterpret_cast <uintptr_t >(GetAncestor (hWnd, GA_ROOTOWNER)));
82
+ break ;
83
+
76
84
case _T (' t' ):
77
85
{
78
86
TCHAR Title[MAX_PATH] = _T (" " );
@@ -116,6 +124,73 @@ void PrintWindow(HWND hWnd, const PrintWindowOptions& print)
116
124
_tprintf (_T (" \n " ));
117
125
}
118
126
127
+ void PrintWindowDetails (HWND hWnd, const PrintWindowOptions& print)
128
+ {
129
+ for (auto c : print.columns )
130
+ {
131
+ switch (c)
132
+ {
133
+ case _T (' h' ):
134
+ _tprintf (_T (" HWND: 0x%08" ) _T (PRIXPTR) _T (" \n " ), reinterpret_cast <uintptr_t >(hWnd));
135
+ break ;
136
+
137
+ case _T (' P' ):
138
+ _tprintf (_T (" Parent: 0x%08" ) _T (PRIXPTR) _T (" \n " ), reinterpret_cast <uintptr_t >(GetParent (hWnd)));
139
+ break ;
140
+
141
+ case _T (' R' ):
142
+ _tprintf (_T (" Root: 0x%08" ) _T (PRIXPTR) _T (" \n " ), reinterpret_cast <uintptr_t >(GetAncestor (hWnd, GA_ROOTOWNER)));
143
+ break ;
144
+
145
+ case _T (' t' ):
146
+ {
147
+ TCHAR Title[MAX_PATH] = _T (" " );
148
+ GetWindowText (hWnd, Title, ARRAYSIZE (Title));
149
+ _tprintf (_T (" Title: \" %s\"\n " ), Title);
150
+ }
151
+ break ;
152
+
153
+ case _T (' c' ):
154
+ {
155
+ TCHAR Class[MAX_PATH] = _T (" " );
156
+ GetClassName (hWnd, Class, ARRAYSIZE (Class));
157
+ _tprintf (_T (" Class: \" %s\"\n " ), Class);
158
+ }
159
+ break ;
160
+
161
+ case _T (' s' ):
162
+ {
163
+ LONG Style = GetWindowLong (hWnd, GWL_STYLE);
164
+ _tprintf (_T (" Style: 0x%08X\n " ), Style );
165
+ }
166
+ break ;
167
+
168
+ case _T (' x' ):
169
+ {
170
+ LONG ExStyle = GetWindowLong (hWnd, GWL_EXSTYLE);
171
+ _tprintf (_T (" ExStyle: 0x%08X\n " ), ExStyle);
172
+ }
173
+ break ;
174
+
175
+ case _T (' p' ):
176
+ {
177
+ DWORD dwProcessId = 0 ;
178
+ GetWindowThreadProcessId (hWnd, &dwProcessId);
179
+ _tprintf (_T (" PID: %d\n " ), dwProcessId);
180
+ }
181
+ break ;
182
+
183
+ case _T (' r' ):
184
+ {
185
+ RECT rc = {};
186
+ GetWindowRect (hWnd, &rc);
187
+ _tprintf (_T (" Rect: { %d, %d, %d, %d } (%d x %d)\n " ), rc.left , rc.top , rc.right , rc.bottom , rc.right - rc.left , rc.bottom - rc.top );
188
+ }
189
+ break ;
190
+ }
191
+ }
192
+ }
193
+
119
194
BOOL CALLBACK GetWindowsEnumWindowsProc (
120
195
_In_ HWND hWnd,
121
196
_In_ LPARAM lParam
@@ -178,6 +253,18 @@ HWND GetWindow(const TCHAR* s)
178
253
GetCursorPos (&pt);
179
254
return WindowFromPoint (pt);
180
255
}
256
+ else if (_tcsicmp (s, _T (" {cursor.parent}" )) == 0 )
257
+ {
258
+ POINT pt;
259
+ GetCursorPos (&pt);
260
+ return GetParent (WindowFromPoint (pt));
261
+ }
262
+ else if (_tcsicmp (s, _T (" {cursor.toplevel}" )) == 0 )
263
+ {
264
+ POINT pt;
265
+ GetCursorPos (&pt);
266
+ return GetAncestor (WindowFromPoint (pt), GA_ROOTOWNER);
267
+ }
181
268
else if (_tcsicmp (s, _T (" {console}" )) == 0 )
182
269
return GetConsoleWindow ();
183
270
else if (_tcsicmp (s, _T (" {foreground}" )) == 0 )
@@ -206,6 +293,8 @@ int _tmain(int argc, const TCHAR* const argv[])
206
293
207
294
_tprintf (_T (" \n where window/parent can be:\n " ));
208
295
_tprintf (_T (" \t {cursor} - window under cursor\n " ));
296
+ _tprintf (_T (" \t {cursor.parent} - \n " ));
297
+ _tprintf (_T (" \t {cursor.toplevel} - \n " ));
209
298
_tprintf (_T (" \t {console} - console window\n " ));
210
299
_tprintf (_T (" \t {foreground} - foreground window\n " ));
211
300
}
@@ -215,9 +304,11 @@ int _tmain(int argc, const TCHAR* const argv[])
215
304
ListWindows (print, GetWindow (wnd), TRUE );
216
305
else if (_tcsicmp (cmd, _T (" print" )) == 0 )
217
306
{
307
+ print.columns = _T (" hpPRctsxr" );
218
308
HWND hWnd = GetWindow (wnd);
219
- PrintWindowHeadings (print);
220
- PrintWindow (hWnd, print);
309
+ // PrintWindowHeadings(print);
310
+ // PrintWindow(hWnd, print);
311
+ PrintWindowDetails (hWnd, print);
221
312
}
222
313
else if (_tcsicmp (cmd, _T (" parent" )) == 0 )
223
314
{
@@ -228,28 +319,6 @@ int _tmain(int argc, const TCHAR* const argv[])
228
319
}
229
320
// "show" ShowWindow();
230
321
// "send" SendMessage();
231
- #if 0
232
- else if (_tcsicmp(cmd, _T("cursor")) == 0)
233
- {
234
- POINT pt;
235
- GetCursorPos(&pt);
236
- HWND hWnd = WindowFromPoint(pt);
237
- PrintWindowHeadings(print);
238
- PrintWindow(hWnd, print);
239
- }
240
- else if (_tcscmp(cmd, _T("console")) == 0)
241
- {
242
- HWND hWnd = GetConsoleWindow();
243
- PrintWindowHeadings(print);
244
- PrintWindow(hWnd, print);
245
- }
246
- else if (_tcscmp(cmd, _T("foreground")) == 0)
247
- {
248
- HWND hWnd = GetForegroundWindow();
249
- PrintWindowHeadings(print);
250
- PrintWindow(hWnd, print);
251
- }
252
- #endif
253
322
else
254
323
_tprintf (_T (" Unknown command \" %s\"\n " ), cmd);
255
324
0 commit comments