4 #include <WinSock2.h>
\r
8 #define LAY_IMPLEMENTATION
\r
12 #include <stdbool.h>
\r
15 #include <windows.h>
\r
16 #include <shlwapi.h>
\r
21 ws::sendRequest("StartRecord");
\r
27 ws::sendRequest("StopRecord");
\r
31 checkProcessRunning(HANDLE handle)
\r
35 if (handle != NULL && GetExitCodeProcess(handle, &exit_code)) {
\r
36 return exit_code == STILL_ACTIVE;
\r
43 getHwndProcess(HWND hwnd)
\r
45 DWORD processId, threadId = GetWindowThreadProcessId(hwnd, &processId);
\r
46 return OpenProcess(PROCESS_QUERY_INFORMATION, false, processId);
\r
49 // HWND getProcessHwnd(HANDLE handle) {}
\r
52 checkFullscreenWindow()
\r
54 HWND desktopHwnd = GetDesktopWindow();
\r
55 HWND fgHwnd = GetForegroundWindow();
\r
57 if (fgHwnd != desktopHwnd && fgHwnd != GetShellWindow()) {
\r
58 RECT windowRect, desktopRect;
\r
59 // Get Window and Desktop size
\r
60 GetWindowRect(fgHwnd, &windowRect);
\r
61 GetWindowRect(desktopHwnd, &desktopRect);
\r
63 bool fullscreen = windowRect.bottom == desktopRect.bottom &&
\r
64 windowRect.top == desktopRect.top &&
\r
65 windowRect.left == desktopRect.left &&
\r
66 windowRect.right == desktopRect.right;
\r
75 checkForegroundProcess(std::string exeName)
\r
77 HWND fgHwnd = GetForegroundWindow();
\r
78 HANDLE fgHandle = getHwndProcess(fgHwnd);
\r
80 char filename[1024];
\r
81 int len = GetModuleFileNameExA(fgHandle, NULL, filename, 1024);
\r
82 PathStripPathA(filename);
\r
84 return strcmp(filename, exeName.c_str()) == 0;
\r
87 bool recording = false;
\r
88 HANDLE process = NULL;
\r
91 // WinMain(HINSTANCE hInstance,
\r
92 // HINSTANCE hPrevInstance,
\r
95 int main(int argc, char **argv)
\r
98 //win::Window window("Title", "MyWindowClass", hInstance);
\r
99 win::Window window("Title", "MyWindowClass", GetModuleHandle(0));
\r
101 lay_context *ctx = &window.ctx;
\r
102 lay_id root = window.lId;
\r
104 lay_id row1 = win::createLayId(&window.ctx, window.lId, 0, 25, LAY_ROW, LAY_LEFT);
\r
105 lay_set_margins_ltrb(ctx, row1, 5, 5, 5, 5);
\r
106 lay_id row2 = win::createLayId(&window.ctx, window.lId, 0, 0, LAY_ROW, LAY_FILL);
\r
107 lay_set_margins_ltrb(ctx, row2, 5, 5, 5, 5);
\r
109 win::CheckBox cbWindowTitle(&window, "Window Title", row1, 100, 25, 0, 0);
\r
110 win::CheckBox cbFullscreenWindow(&window, "Any Fullscreen Application", row1, 200, 25, 0, 0);
\r
112 win::Button btnConnect(&window, "Connect", row1, 100, 25, 0, 0);
\r
113 btnConnect.onClick([&]() {
\r
114 ws::connect("ws://127.0.0.1:4444");
\r
117 win::ListBox lstActiveProcesses(&window, row2, 0, 0, 0, LAY_FILL);
\r
119 lay_id col1 = win::createLayId(&window.ctx, row2, 80, 0, LAY_COLUMN, LAY_VCENTER);
\r
120 lay_set_margins_ltrb(ctx, col1, 5, 0, 5, 0);
\r
122 win::ListBox lstMonitoredProcesses(&window, row2, 0, 0, 0, LAY_FILL);
\r
123 lstActiveProcesses.addStyle(WS_VSCROLL);
\r
124 lstMonitoredProcesses.addStyle(WS_VSCROLL);
\r
126 win::Button btnUpdateWindows(&window, "Update", col1, 85, 25, 0, 0);
\r
127 win::Button btnStartMonitoringName(&window, "Exe name >>", col1, 85, 25, 0, 0);
\r
128 win::Button btnStartMonitoringPath(&window, "Full path >>", col1, 85, 25, 0, 0);
\r
129 win::Button btnStopMonitoring(&window, "Remove", col1, 85, 25, 0, 0);
\r
130 btnUpdateWindows.onClick([&]() {
\r
131 lstActiveProcesses.clear();
\r
132 for (HWND hwnd = GetTopWindow(NULL); hwnd != nullptr;
\r
133 hwnd = GetNextWindow(hwnd, GW_HWNDNEXT)) {
\r
134 if (!IsWindowVisible(hwnd))
\r
138 GetWindowRect(hwnd, &rect);
\r
141 if (GetModuleFileNameExA(getHwndProcess(hwnd), 0, str, 1024) != 0 &&
\r
142 lstActiveProcesses.findString(str) == LB_ERR) {
\r
143 lstActiveProcesses.addString(str);
\r
147 btnStartMonitoringName.onClick([&]() {
\r
148 int sel = lstActiveProcesses.getSelectedIndex();
\r
149 if (sel < 0) return;
\r
151 std::string selStr = lstActiveProcesses.getText(sel);
\r
153 char *filename = new char[selStr.size()];
\r
154 std::memcpy(filename, selStr.c_str(), selStr.size());
\r
155 PathStripPathA(filename);
\r
157 if (lstMonitoredProcesses.findString(std::string(filename)) == LB_ERR)
\r
158 lstMonitoredProcesses.addString(std::string(filename));
\r
162 btnStartMonitoringPath.onClick([&]() {
\r
163 int sel = lstActiveProcesses.getSelectedIndex();
\r
164 if (sel < 0) return;
\r
165 std::string selStr = lstActiveProcesses.getText(sel);
\r
166 if (lstMonitoredProcesses.findString(selStr) == LB_ERR)
\r
167 lstMonitoredProcesses.addString(selStr);
\r
169 btnStopMonitoring.onClick([&]() {
\r
170 int sel = lstMonitoredProcesses.getSelectedIndex();
\r
171 if (sel < 0) return;
\r
172 lstMonitoredProcesses.remove(sel);
\r
179 SetTimer(window.hwnd, 10123, 100, [](HWND, UINT, UINT_PTR, DWORD) {
\r
181 if (checkForegroundProcess("League of Legends.exe")) {
\r
183 process = getHwndProcess(GetForegroundWindow());
\r
187 if (!checkProcessRunning(process)) {
\r
195 while (window.update()) {
\r