Skip to content

Commit 7ddbdb0

Browse files
committed
Added Sleep
1 parent a7d5bd0 commit 7ddbdb0

File tree

3 files changed

+118
-26
lines changed

3 files changed

+118
-26
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ Use the [SendMessage](https://docs.microsoft.com/en-us/windows/win32/api/winuser
101101
## [Shortcut](Shortcut.cpp)
102102
Edit shortcut properties from the command line.
103103

104+
## [Sleep](Sleep.cpp)
105+
Sleep in seconds.
106+
104107
## [TimeStamp](TimeStamp.cpp)
105108
Copies stdin to stdout prepending each line with a timestamp.
106109

Sleep.cpp

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include <cstdio>
2+
#include <Windows.h>
3+
#include <tchar.h>
4+
#include "arg.inl"
5+
6+
int _tmain(int argc, const TCHAR* argv[])
7+
{
8+
arginit(argc, argv);
9+
const DWORD sleep_ms = _ttoi(argnum(1, _T("0"))) * 1000;
10+
if (!argcleanup() || sleep_ms == 0)
11+
{
12+
_ftprintf(stderr, _T("Usage: %s <time_in_sec> \n"), argapp());
13+
return EXIT_FAILURE;
14+
}
15+
16+
//_tprintf(_T("Calling the sleep function for %d ms\n"), sleep_ms);
17+
18+
Sleep(sleep_ms);
19+
return EXIT_SUCCESS;
20+
}

WndList.cpp

+95-26
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,14 @@ void PrintWindowHeadings(const PrintWindowOptions& print)
2727
_tprintf(_T("%-10s"), _T("HANDLE"));
2828
break;
2929

30-
case _T('a'):
30+
case _T('P'):
3131
_tprintf(_T("%-10s"), _T("PARENT"));
3232
break;
3333

34+
case _T('R'):
35+
_tprintf(_T("%-10s"), _T("ROOT"));
36+
break;
37+
3438
case _T('t'):
3539
_tprintf(_T("%s"), _T("TITLE"));
3640
break;
@@ -69,10 +73,14 @@ void PrintWindow(HWND hWnd, const PrintWindowOptions& print)
6973
_tprintf(_T("0x%08") _T(PRIXPTR), reinterpret_cast<uintptr_t>(hWnd));
7074
break;
7175

72-
case _T('a'):
76+
case _T('P'):
7377
_tprintf(_T("0x%08") _T(PRIXPTR), reinterpret_cast<uintptr_t>(GetParent(hWnd)));
7478
break;
7579

80+
case _T('R'):
81+
_tprintf(_T("0x%08") _T(PRIXPTR), reinterpret_cast<uintptr_t>(GetAncestor(hWnd, GA_ROOTOWNER)));
82+
break;
83+
7684
case _T('t'):
7785
{
7886
TCHAR Title[MAX_PATH] = _T("");
@@ -116,6 +124,73 @@ void PrintWindow(HWND hWnd, const PrintWindowOptions& print)
116124
_tprintf(_T("\n"));
117125
}
118126

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+
119194
BOOL CALLBACK GetWindowsEnumWindowsProc(
120195
_In_ HWND hWnd,
121196
_In_ LPARAM lParam
@@ -178,6 +253,18 @@ HWND GetWindow(const TCHAR* s)
178253
GetCursorPos(&pt);
179254
return WindowFromPoint(pt);
180255
}
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+
}
181268
else if (_tcsicmp(s, _T("{console}")) == 0)
182269
return GetConsoleWindow();
183270
else if (_tcsicmp(s, _T("{foreground}")) == 0)
@@ -206,6 +293,8 @@ int _tmain(int argc, const TCHAR* const argv[])
206293

207294
_tprintf(_T("\nwhere window/parent can be:\n"));
208295
_tprintf(_T("\t{cursor} - window under cursor\n"));
296+
_tprintf(_T("\t{cursor.parent} - \n"));
297+
_tprintf(_T("\t{cursor.toplevel} - \n"));
209298
_tprintf(_T("\t{console} - console window\n"));
210299
_tprintf(_T("\t{foreground} - foreground window\n"));
211300
}
@@ -215,9 +304,11 @@ int _tmain(int argc, const TCHAR* const argv[])
215304
ListWindows(print, GetWindow(wnd), TRUE);
216305
else if (_tcsicmp(cmd, _T("print")) == 0)
217306
{
307+
print.columns = _T("hpPRctsxr");
218308
HWND hWnd = GetWindow(wnd);
219-
PrintWindowHeadings(print);
220-
PrintWindow(hWnd, print);
309+
//PrintWindowHeadings(print);
310+
//PrintWindow(hWnd, print);
311+
PrintWindowDetails(hWnd, print);
221312
}
222313
else if (_tcsicmp(cmd, _T("parent")) == 0)
223314
{
@@ -228,28 +319,6 @@ int _tmain(int argc, const TCHAR* const argv[])
228319
}
229320
// "show" ShowWindow();
230321
// "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
253322
else
254323
_tprintf(_T("Unknown command \"%s\"\n"), cmd);
255324

0 commit comments

Comments
 (0)