]> gitweb.ps.run Git - autorec/blobdiff - src/main.cpp
MVP
[autorec] / src / main.cpp
index f4a47f314e3b446aaebaebfd7b57e4887be8625a..5056acf844a0b702d4de597004f95c7909942eda 100644 (file)
 void\r
 startRecording()\r
 {\r
-  MessageBoxA(NULL, "Start", "Start Start", MB_OK);\r
+  ws::sendRequest("StartRecord");\r
 }\r
 \r
 void\r
 stopRecording()\r
 {\r
-  MessageBoxA(NULL, "Stop", "Stop Stop", MB_OK);\r
+  ws::sendRequest("StopRecord");\r
 }\r
 \r
 bool\r
@@ -74,17 +74,20 @@ checkFullscreenWindow()
 }\r
 \r
 bool\r
-checkNotepadWindow()\r
+checkForegroundProcess(std::string exeName)\r
 {\r
   HWND fgHwnd = GetForegroundWindow();\r
   HANDLE fgHandle = getHwndProcess(fgHwnd);\r
 \r
   char filename[1024];\r
   int len = GetModuleFileNameExA(fgHandle, NULL, filename, 1024);\r
+  PathStripPathA(filename);\r
 \r
-  return strcmp(filename, "C:\\Windows\\System32\\notepad.exe") == 0;\r
+  return strcmp(filename, exeName.c_str()) == 0;\r
 }\r
 \r
+bool recording = false;\r
+HANDLE process = NULL;\r
 \r
 int WINAPI\r
 WinMain(HINSTANCE hInstance,\r
@@ -92,8 +95,6 @@ WinMain(HINSTANCE hInstance,
         LPSTR lpCmdLine,\r
         int nCmdShow)\r
 {\r
-  bool recording = false;\r
-  HANDLE process = NULL;\r
 \r
   HWND window = win::Window("Title", "MyWindowClass", hInstance);\r
 \r
@@ -108,6 +109,7 @@ WinMain(HINSTANCE hInstance,
   lay_set_size_xy(&win::_::ctx, row2, 0, 0);\r
   lay_set_behave(&win::_::ctx, row2, LAY_FILL);\r
   lay_set_contain(&win::_::ctx, row2, LAY_ROW);\r
+  lay_set_margins_ltrb(&win::_::ctx, row2, 5, 5, 5, 5);\r
   lay_id col1 = lay_item(&win::_::ctx);\r
   lay_set_size_xy(&win::_::ctx, col1, 80, 0);\r
   lay_set_behave(&win::_::ctx, col1, LAY_VCENTER);\r
@@ -121,11 +123,6 @@ WinMain(HINSTANCE hInstance,
   win::Callback(btnConnect, BN_CLICKED, [&]() {\r
     ws::connect("ws://127.0.0.1:4444");\r
   });\r
-  \r
-  HWND btnIdentify = win::Button(window, "Identify", row1, 100, 25, 0, 0);\r
-  win::Callback(btnIdentify, BN_CLICKED, [&]() {\r
-    ws::identify();\r
-  });\r
 \r
   win::Callback(cbWindowTitle, BN_CLICKED, [&]() {\r
     SendMessageA(cbWindowTitle, BM_SETCHECK, SendMessageA(cbWindowTitle, BM_GETCHECK, 0, 0) ? BST_UNCHECKED : BST_CHECKED, 0);\r
@@ -134,7 +131,7 @@ WinMain(HINSTANCE hInstance,
     SendMessageA(cbFullscreenWindow, BM_SETCHECK, SendMessageA(cbFullscreenWindow, BM_GETCHECK, 0, 0) ? BST_UNCHECKED : BST_CHECKED, 0);\r
   });\r
 \r
-  HWND lstActiveProcesses = win::ListBox(window, row2, 0, 0, 0, LAY_FILL);\r
+  HWND lstActiveProcesses = win::ListView(window, row2, 0, 0, 0, LAY_FILL);\r
   lay_insert(&win::_::ctx, row2, col1);\r
   HWND lstMonitoredProcesses = win::ListBox(window, row2, 0, 0, 0, LAY_FILL);\r
   win::AddStyle(lstActiveProcesses, WS_VSCROLL);\r
@@ -189,28 +186,27 @@ WinMain(HINSTANCE hInstance,
     win::ListRemove(lstMonitoredProcesses, sel);\r
   });\r
 \r
-\r
-  win::ShowNotificationIcon(hInstance, window);\r
-\r
   win::ShowWindow(window);\r
 \r
   ws::init();\r
 \r
-  while (win::UpdateWindow(window)) {\r
-    ws::update();\r
-\r
+  SetTimer(window, 10123, 100, [](HWND, UINT, UINT_PTR, DWORD) {\r
     if (!recording) {\r
-      if (checkNotepadWindow()) {\r
+      if (checkForegroundProcess("League of Legends.exe")) {\r
+        recording = true;\r
         process = getHwndProcess(GetForegroundWindow());\r
         startRecording();\r
-        recording = true;\r
       }\r
     } else {\r
       if (!checkProcessRunning(process)) {\r
+        recording = false;\r
         process = NULL;\r
         stopRecording();\r
-        recording = false;\r
       }\r
     }\r
+  });\r
+\r
+  while (win::UpdateWindow(window)) {\r
+    ws::update();\r
   }\r
 }\r