]> gitweb.ps.run Git - autorec/blobdiff - src/win.h
Merge branch 'main' of ps.run:autorec
[autorec] / src / win.h
index b8763ea54ffc09ad85fae46fae61c2fe753205c1..0a734c95da3d4c2dadfa725d8211003dfbba9362 100644 (file)
--- a/src/win.h
+++ b/src/win.h
@@ -1,7 +1,3 @@
-#pragma comment(linker, "\"/manifestdependency:type='win32' \\r
-name='Microsoft.Windows.Common-Controls' version='6.0.0.0' \\r
-processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")\r
-\r
 #include <windows.h>\r
 #include <CommCtrl.h>\r
 \r
@@ -42,6 +38,10 @@ namespace win
     {\r
       SetWindowLongPtrA(hwnd, GWL_STYLE, getStyle() & (~style));\r
     }\r
+    void setActive(bool active)\r
+    {\r
+      EnableWindow(hwnd, active);\r
+    }\r
   };\r
   struct Window : Hwnd\r
   {\r
@@ -95,6 +95,12 @@ namespace win
       std::vector<\r
         std::function<void(HWND, UINT, WPARAM, LPARAM)>>> handlers;\r
 \r
+    struct Timer {\r
+      bool active = true;\r
+      std::function<void()> f;\r
+    };\r
+    std::vector<Timer> timers;\r
+\r
     Window(std::string title, std::string className, HINSTANCE hInstance)\r
     {\r
       WNDCLASSEXA wc;\r
@@ -155,6 +161,19 @@ namespace win
         },\r
         0);\r
     }\r
+    void setTimer(UINT interval, std::function<void()> cb)\r
+    {\r
+      SetTimer(this->hwnd, timers.size() + 1000, interval, [](HWND hwnd, UINT uMsg, UINT_PTR uIdEvent, DWORD dwTime) {\r
+        Window *window = (Window*)GetWindowLongPtrA(hwnd, 0);\r
+        if (window == nullptr)\r
+          return;\r
+\r
+        window->timers[uIdEvent-1000].f();\r
+      });\r
+      Timer t;\r
+      t.f = cb;\r
+      timers.push_back(t);\r
+    }\r
   };\r
 \r
   struct Button : Hwnd\r