-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgzap.c
81 lines (63 loc) · 2.15 KB
/
gzap.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// cc gzap.c -o gzap -ldwmapi -s -mwindows
#include <dwmapi.h>
#include <stdio.h>
#include <windows.h>
RECT workarea;
int padding = 5;
int keep = 0;
BOOL IsOpenedWindow(HWND hwnd) {
HWND hwndTry, hwndWalk = NULL;
if (!IsWindowVisible(hwnd)) return 0;
if (IsIconic(hwnd)) return 0;
hwndTry = GetAncestor(hwnd, GA_ROOTOWNER);
while (hwndTry != hwndWalk) {
hwndWalk = hwndTry;
hwndTry = GetLastActivePopup(hwndWalk);
if (IsWindowVisible(hwndTry)) break;
}
if (hwndWalk != hwnd) return 0;
TITLEBARINFO ti;
ti.cbSize = sizeof(ti);
GetTitleBarInfo(hwnd, &ti);
if (ti.rgstate[0] & STATE_SYSTEM_INVISIBLE) return 0;
if (GetWindowLongA(hwnd, GWL_EXSTYLE) & WS_EX_TOOLWINDOW) return 0;
wchar_t cls[32];
GetClassNameW(hwnd, cls, sizeof(cls));
if (wcscmp(cls, L"ApplicationFrameWindow") == 0) {
DWORD cloaked;
DwmGetWindowAttribute(hwnd, DWMWA_CLOAKED, &cloaked, sizeof(cloaked));
if (cloaked != 0) return 0;
}
return 1;
}
static BOOL CALLBACK enumWindowCallback(HWND hWnd, LPARAM lparam) {
if (IsOpenedWindow(hWnd)) {
RECT rect;
RECT rect2;
DwmGetWindowAttribute(hWnd, DWMWA_EXTENDED_FRAME_BOUNDS, &rect, sizeof(rect));
GetWindowRect(hWnd, &rect2);
int x = rect.left + padding;
int y = rect.top + padding;
int w = rect.right - x - padding;
int h = rect.bottom - y - padding;
x += (workarea.left == rect.left) ? padding : 0;
y += (workarea.top == rect.top) ? padding : 0;
w -= ((workarea.right == rect.right) ? padding : 0) + ((workarea.left == rect.left) ? padding : 0);
h -= ((workarea.bottom == rect.bottom) ? padding : 0) + ((workarea.top == rect.top) ? padding : 0);
// windows is amazing
x -= (rect.left - rect2.left);
y -= (rect.top - rect2.top);
w -= (rect.right - rect2.right) * 2;
h -= (rect.bottom - rect2.bottom);
if (!keep) ShowWindow(hWnd, SW_NORMAL);
SetWindowPos(hWnd, NULL, x, y, w, h, 0x0200);
}
return TRUE;
}
int main(int argc, char *argv[]) {
if (argc > 1) padding = atoi(argv[1]);
if (argc > 2 && atoi(argv[2])) keep = 1;
SystemParametersInfo(SPI_GETWORKAREA, 0, &workarea, 0);
EnumWindows(enumWindowCallback, 0);
return 0;
}