4 #include <WinSock2.h>
\r
8 #include "../res/resource.h"
\r
10 #define LAY_IMPLEMENTATION
\r
14 #include <stdbool.h>
\r
17 #include <windows.h>
\r
18 #include <shlwapi.h>
\r
23 ws::sendRequest("StartRecord");
\r
29 ws::sendRequest("StopRecord");
\r
33 checkProcessRunning(HANDLE handle)
\r
37 if (handle != NULL && GetExitCodeProcess(handle, &exit_code)) {
\r
38 return exit_code == STILL_ACTIVE;
\r
45 getHwndProcess(HWND hwnd)
\r
47 DWORD processId, threadId = GetWindowThreadProcessId(hwnd, &processId);
\r
48 return OpenProcess(PROCESS_QUERY_INFORMATION, false, processId);
\r
51 // HWND getProcessHwnd(HANDLE handle) {}
\r
54 checkFullscreenWindow()
\r
56 HWND desktopHwnd = GetDesktopWindow();
\r
57 HWND fgHwnd = GetForegroundWindow();
\r
59 if (fgHwnd != desktopHwnd && fgHwnd != GetShellWindow()) {
\r
60 RECT windowRect, desktopRect;
\r
61 // Get Window and Desktop size
\r
62 GetWindowRect(fgHwnd, &windowRect);
\r
63 GetWindowRect(desktopHwnd, &desktopRect);
\r
65 bool fullscreen = windowRect.bottom == desktopRect.bottom &&
\r
66 windowRect.top == desktopRect.top &&
\r
67 windowRect.left == desktopRect.left &&
\r
68 windowRect.right == desktopRect.right;
\r
77 checkForegroundProcess(std::string exeName)
\r
79 HWND fgHwnd = GetForegroundWindow();
\r
80 HANDLE fgHandle = getHwndProcess(fgHwnd);
\r
82 char filename[1024];
\r
83 int len = GetModuleFileNameExA(fgHandle, NULL, filename, 1024);
\r
84 PathStripPathA(filename);
\r
86 return strcmp(filename, exeName.c_str()) == 0;
\r
89 bool recording = false;
\r
90 HANDLE process = NULL;
\r
93 WinMain(HINSTANCE hInstance,
\r
94 HINSTANCE hPrevInstance,
\r
99 HWND window = win::Window("Title", "MyWindowClass", hInstance);
\r
101 lay_id row1 = lay_item(&win::_::ctx);
\r
102 lay_insert(&win::_::ctx, win::_::root, row1);
\r
103 lay_set_size_xy(&win::_::ctx, row1, 0, 25);
\r
104 lay_set_behave(&win::_::ctx, row1, LAY_LEFT);
\r
105 lay_set_contain(&win::_::ctx, row1, LAY_ROW);
\r
106 lay_set_margins_ltrb(&win::_::ctx, row1, 5, 5, 5, 5);
\r
107 lay_id row2 = lay_item(&win::_::ctx);
\r
108 lay_insert(&win::_::ctx, win::_::root, row2);
\r
109 lay_set_size_xy(&win::_::ctx, row2, 0, 0);
\r
110 lay_set_behave(&win::_::ctx, row2, LAY_FILL);
\r
111 lay_set_contain(&win::_::ctx, row2, LAY_ROW);
\r
112 lay_set_margins_ltrb(&win::_::ctx, row2, 5, 5, 5, 5);
\r
113 lay_id col1 = lay_item(&win::_::ctx);
\r
114 lay_set_size_xy(&win::_::ctx, col1, 80, 0);
\r
115 lay_set_behave(&win::_::ctx, col1, LAY_VCENTER);
\r
116 lay_set_contain(&win::_::ctx, col1, LAY_COLUMN);
\r
117 lay_set_margins_ltrb(&win::_::ctx, col1, 5, 0, 5, 0);
\r
119 HWND cbWindowTitle = win::CheckBox(window, "Window Title", row1, 100, 25, 0, 0);
\r
120 HWND cbFullscreenWindow = win::CheckBox(window, "Any Fullscreen Application", row1, 200, 25, 0, 0);
\r
122 HWND btnConnect = win::Button(window, "Connect", row1, 100, 25, 0, 0);
\r
123 win::Callback(btnConnect, BN_CLICKED, [&]() {
\r
124 ws::connect("ws://127.0.0.1:4444");
\r
127 win::Callback(cbWindowTitle, BN_CLICKED, [&]() {
\r
128 SendMessageA(cbWindowTitle, BM_SETCHECK, SendMessageA(cbWindowTitle, BM_GETCHECK, 0, 0) ? BST_UNCHECKED : BST_CHECKED, 0);
\r
130 win::Callback(cbFullscreenWindow, BN_CLICKED, [&]() {
\r
131 SendMessageA(cbFullscreenWindow, BM_SETCHECK, SendMessageA(cbFullscreenWindow, BM_GETCHECK, 0, 0) ? BST_UNCHECKED : BST_CHECKED, 0);
\r
134 HWND lstActiveProcesses = win::ListView(window, row2, 0, 0, 0, LAY_FILL);
\r
135 lay_insert(&win::_::ctx, row2, col1);
\r
136 HWND lstMonitoredProcesses = win::ListBox(window, row2, 0, 0, 0, LAY_FILL);
\r
137 win::AddStyle(lstActiveProcesses, WS_VSCROLL);
\r
138 win::AddStyle(lstMonitoredProcesses, WS_VSCROLL);
\r
140 HWND btnUpdateWindows = win::Button(window, "Update", col1, 85, 25, 0, 0);
\r
141 HWND btnStartMonitoringName = win::Button(window, "Exe name >>", col1, 85, 25, 0, 0);
\r
142 HWND btnStartMonitoringPath = win::Button(window, "Full path >>", col1, 85, 25, 0, 0);
\r
143 HWND btnStopMonitoring = win::Button(window, "Remove", col1, 85, 25, 0, 0);
\r
144 win::Callback(btnUpdateWindows, BN_CLICKED, [&]() {
\r
145 win::ListClear(lstActiveProcesses);
\r
146 for (HWND hwnd = GetTopWindow(NULL); hwnd != nullptr;
\r
147 hwnd = GetNextWindow(hwnd, GW_HWNDNEXT)) {
\r
148 if (!IsWindowVisible(hwnd))
\r
152 GetWindowRect(hwnd, &rect);
\r
155 if (GetModuleFileNameExA(getHwndProcess(hwnd), 0, str, 1024) != 0 &&
\r
156 win::ListFindString(lstActiveProcesses, str) == LB_ERR) {
\r
157 win::ListAddString(lstActiveProcesses, str);
\r
161 win::Callback(btnStartMonitoringName, BN_CLICKED, [&]() {
\r
162 int sel = win::ListGetSelectedIndex(lstActiveProcesses);
\r
163 if (sel < 0) return;
\r
165 std::string selStr = win::ListGetText(lstActiveProcesses, sel);
\r
167 char *filename = new char[selStr.size()];
\r
168 std::memcpy(filename, selStr.c_str(), selStr.size());
\r
169 PathStripPathA(filename);
\r
171 if (win::ListFindString(lstMonitoredProcesses, std::string(filename)) == LB_ERR)
\r
172 win::ListAddString(lstMonitoredProcesses, std::string(filename));
\r
176 win::Callback(btnStartMonitoringPath, BN_CLICKED, [&]() {
\r
177 int sel = win::ListGetSelectedIndex(lstActiveProcesses);
\r
178 if (sel < 0) return;
\r
179 std::string selStr = win::ListGetText(lstActiveProcesses, sel);
\r
180 if (win::ListFindString(lstMonitoredProcesses, selStr) == LB_ERR)
\r
181 win::ListAddString(lstMonitoredProcesses, selStr);
\r
183 win::Callback(btnStopMonitoring, BN_CLICKED, [&]() {
\r
184 int sel = win::ListGetSelectedIndex(lstMonitoredProcesses);
\r
185 if (sel < 0) return;
\r
186 win::ListRemove(lstMonitoredProcesses, sel);
\r
189 win::ShowWindow(window);
\r
193 SetTimer(window, 10123, 100, [](HWND, UINT, UINT_PTR, DWORD) {
\r
195 if (checkForegroundProcess("League of Legends.exe")) {
\r
197 process = getHwndProcess(GetForegroundWindow());
\r
201 if (!checkProcessRunning(process)) {
\r
209 while (win::UpdateWindow(window)) {
\r