-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWindowResizer.cpp
More file actions
executable file
·96 lines (88 loc) · 2.46 KB
/
WindowResizer.cpp
File metadata and controls
executable file
·96 lines (88 loc) · 2.46 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include "WindowResizer.h"
#include <iostream>
#define vector std::vector
#define endl std::endl
#define cout std::cout
#define uint unsigned int
vector<HWND> windowHandles;
vector<std::string> windowNames;
vector<RECT> monitors;
BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam) //get all windows
{
if (IsWindowVisible(hwnd) && (GetWindowLong(hwnd, GWL_STYLE) & WS_EX_APPWINDOW)) {
windowHandles.push_back(hwnd);
char temp[100];
GetWindowText(hwnd, temp, 100);
windowNames.push_back(std::string(temp));
}
return 1;
}
BOOL CALLBACK MonitorEnumProc(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData)//get all displays
{
MONITORINFO info;
info.cbSize = sizeof(info);
if (GetMonitorInfo(hMonitor, &info))
monitors.push_back(info.rcWork);
return 1;
}
vector<RECT> parts() {
vector<RECT> res;
for (RECT curr : monitors) {
int top = curr.top;
int bottom = curr.bottom;
int left = curr.left;
int right = curr.right;
int halfH = (top + bottom) / 2;
int halfW = std::abs((left + right) / 2);
for (int i = 1; i <= 2; i++) {
for (int j = 1; j <= 2; j++) {
RECT temp = {};
temp.top = top;
temp.bottom = halfH;
temp.left = left;
temp.right = halfW;
res.push_back(temp);
left = (left + halfW);
}
left = curr.left;
top = (halfH + top);
}
}
return res;
}
WindowResizer::WindowResizer(BOOL debug) {
EnumDisplayMonitors(NULL, NULL, MonitorEnumProc, NULL);
EnumWindows(EnumWindowsProc, NULL);
vector<RECT> part = parts();
int x = 0;
for (HWND handle : windowHandles) {
if (x >= part.size()) x = 0;
if (debug) {
cout << "LEFT= "<< part.at(x).left << " RIGHT= " << part.at(x).right << " TOP= " << part.at(x).top << " BOTTOM= " << part.at(x).bottom << endl;
char temp[100];
GetWindowText(handle, temp, 100);
cout << temp << endl << endl;
}
SetWindowPos(handle, NULL, part.at(x).left, part.at(x).top, part.at(x).right, part.at(x).bottom, NULL);
x++;
}
}
int main()
{
BOOL dBug = 1;
WindowResizer wR = WindowResizer(dBug);
if (dBug) {
cout << "debug boolean is true";
cout << endl;
for (std::string s : windowNames) {
cout << s << endl;
}
cout << endl;
for (RECT part : monitors) {
cout << part.left << " " << part.right << " " << part.top << " " << part.bottom << endl;
}
}
//MessageBoxA(NULL, "yeet", "warningbox yea bro", MB_ICONWARNING | MB_OK);
char a;
std::cin >> a;
}