-cl /EHsc src/main.cpp src/mongoose.c /I ../libs/websocketpp/ /I ../libs/asio/asio/include /link user32.lib gdi32.lib shell32.lib Shlwapi.lib ws2_32.lib\r
+\r
+REM cl src/mongoose.c -c\r
+\r
+cl /EHsc src/main.cpp mongoose.obj /link user32.lib gdi32.lib shell32.lib Shlwapi.lib ws2_32.lib\r
mt -manifest .\main.exe.manifest -outputresource:main.exe;1
\ No newline at end of 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
}\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
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
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
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
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
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
using std::string;\r
\r
namespace win {\r
-struct Length\r
-{\r
- int pixel;\r
- float percent;\r
-};\r
-struct Size\r
-{\r
- Length x, y, w, h;\r
- int getX(HWND hwnd)\r
- {\r
- RECT rect;\r
- GetClientRect(hwnd, &rect);\r
- return x.percent * (rect.right - rect.left) + x.pixel;\r
- }\r
- int getY(HWND hwnd)\r
- {\r
- RECT rect;\r
- GetClientRect(hwnd, &rect);\r
- return y.percent * (rect.bottom - rect.top) + y.pixel;\r
- }\r
- int getW(HWND hwnd)\r
- {\r
- RECT rect;\r
- GetClientRect(hwnd, &rect);\r
- return w.percent * (rect.right - rect.left) + w.pixel;\r
- }\r
- int getH(HWND hwnd, int _w, int _h)\r
- {\r
- RECT rect;\r
- GetWindowRect(hwnd, &rect);\r
- return h.percent * (rect.bottom - rect.top) + h.pixel;\r
- }\r
-};\r
-\r
namespace _ {\r
using CallbackFn = std::function<void()>;\r
std::map<HWND, std::map<WORD, CallbackFn>> handlers;\r
std::map<HWND, lay_id> lIds;\r
\r
NOTIFYICONDATA niData = { 0 };\r
+void\r
+ShowNotificationIcon()\r
+{\r
+ Shell_NotifyIconA(NIM_ADD, &_::niData);\r
+ Shell_NotifyIconA(NIM_SETVERSION, &_::niData);\r
+}\r
+\r
+void\r
+HideNotificationIcon()\r
+{\r
+ Shell_NotifyIconA(NIM_DELETE, &_::niData);\r
+}\r
\r
lay_context ctx;\r
lay_id root;\r
break;\r
case WM_SIZE:\r
if (wParam == SIZE_MINIMIZED) {\r
+ ShowNotificationIcon();\r
ShowWindow(hwnd, false);\r
- SetForegroundWindow(hwnd);\r
- SetActiveWindow(hwnd);\r
}\r
else {\r
lay_set_size_xy(&_::ctx, _::root, LOWORD(lParam), HIWORD(lParam));\r
case WM_NOTIFY:\r
break;\r
case WM_APP + 1:\r
- if (LOWORD(lParam) == NIN_SELECT)\r
+ if (LOWORD(lParam) == NIN_SELECT) {\r
+ HideNotificationIcon();\r
ShowWindow(hwnd, true);\r
+ SetForegroundWindow(hwnd);\r
+ SetActiveWindow(hwnd);\r
+ }\r
break;\r
case WM_CTLCOLORSTATIC:\r
return (LONG)GetStockObject(WHITE_BRUSH);\r
}\r
}\r
\r
-void\r
-ShowNotificationIcon(HINSTANCE hInstance, HWND hwnd)\r
-{\r
- _::niData.cbSize = sizeof(_::niData);\r
- _::niData.uID = 12345;\r
- _::niData.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;\r
- _::niData.hIcon = LoadIconA(nullptr, IDI_WINLOGO);\r
- _::niData.hWnd = hwnd;\r
- _::niData.uCallbackMessage = WM_APP+1;\r
- _::niData.uVersion = NOTIFYICON_VERSION_4;\r
-\r
- Shell_NotifyIconA(NIM_ADD, &_::niData);\r
- Shell_NotifyIconA(NIM_SETVERSION, &_::niData);\r
-}\r
\r
void\r
Callback(HWND hwnd, WORD ev, std::function<void()> cb)\r
lay_init_context(&_::ctx);\r
_::root = lay_item(&_::ctx);\r
lay_set_contain(&_::ctx, _::root, LAY_COLUMN);\r
- lay_set_margins_ltrb(&_::ctx, _::root, 5, 5, 5, 5);\r
\r
- return CreateWindowA(className.c_str(),\r
+ HWND result = CreateWindowA(className.c_str(),\r
title.c_str(),\r
WS_OVERLAPPEDWINDOW,\r
CW_USEDEFAULT,\r
nullptr,\r
hInstance,\r
nullptr);\r
+ \r
+ _::niData.cbSize = sizeof(_::niData);\r
+ _::niData.uID = 12345;\r
+ _::niData.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;\r
+ _::niData.hIcon = LoadIconA(nullptr, IDI_WINLOGO);\r
+ _::niData.hWnd = result;\r
+ _::niData.uCallbackMessage = WM_APP+1;\r
+ _::niData.uVersion = NOTIFYICON_VERSION_4;\r
+\r
+ return result;\r
}\r
\r
bool\r
SendMessageA(hwnd, LB_DELETESTRING, index, 0);\r
}\r
\r
+HWND\r
+ListView(HWND hwnd, lay_id parent, lay_scalar w, lay_scalar h, uint32_t contain, uint32_t behave)\r
+{\r
+ lay_id lId = lay_item(&_::ctx);\r
+ lay_insert(&_::ctx, parent, lId);\r
+ lay_set_size_xy(&_::ctx, lId, w, h);\r
+ lay_set_contain(&_::ctx, lId, contain);\r
+ lay_set_behave(&_::ctx, lId, behave);\r
+\r
+ HWND result = CreateWindowExA(0,\r
+ WC_LISTVIEWA,\r
+ "",\r
+ WS_VISIBLE | WS_CHILD | WS_BORDER | WS_VSCROLL,\r
+ 0, 0, 0, 0,\r
+ hwnd,\r
+ nullptr,\r
+ nullptr,\r
+ nullptr);\r
+ _::lIds[result] = lId;\r
+ return result;\r
+}\r
+\r
HWND\r
CheckBox(HWND hwnd, string title, lay_id parent, lay_scalar w, lay_scalar h, uint32_t contain, uint32_t behave)\r
{\r
-// #define _WEBSOCKETPP_CPP11_INTERNAL_\r
-// #define ASIO_STANDALONE\r
-// #include <websocketpp/config/asio_no_tls_client.hpp>\r
-// #include <websocketpp/client.hpp>\r
-\r
-// using client = websocketpp::client<websocketpp::config::asio_client>;\r
-\r
#include "mongoose.h"\r
\r
#include "json.hpp"\r
\r
namespace ws\r
{\r
- // client c;\r
-\r
- // void on_message(websocketpp::connection_hdl hdl, client::message_ptr msg) {\r
- // auto j = json::parse(msg->get_payload());\r
- // int op = j["op"].get<int>();\r
-\r
- // if (op == 0) {\r
- // json response = { { "op", 1 },\r
- // { "d", {\r
- // { "rpcVersion", 1 },\r
- // } } };\r
- // auto responseStr = response.dump();\r
- // websocketpp::lib::error_code ec;\r
- // c.send(hdl, responseStr, websocketpp::frame::opcode::TEXT, ec);\r
- // if (ec)\r
- // MessageBoxA(NULL, ec.message().c_str(), "error", MB_OK);\r
- // } else if (op == 2) {\r
- // MessageBoxA(NULL, "hura", "connected", MB_OK);\r
- // }\r
- // }\r
-\r
- // void init()\r
- // {\r
- // c.set_access_channels(websocketpp::log::alevel::all);\r
- // c.clear_access_channels(websocketpp::log::alevel::frame_payload);\r
- // c.set_error_channels(websocketpp::log::elevel::all);\r
-\r
- // // Initialize ASIO\r
- // c.init_asio();\r
-\r
- // // Register our message handler\r
- // c.set_message_handler(&on_message);\r
- // }\r
-\r
- // void connect(std::string address)\r
- // {\r
- // websocketpp::lib::error_code ec;\r
- // client::connection_ptr con = c.get_connection(address, ec);\r
- // if (ec) {\r
- // std::cout << "could not create connection because: " << ec.message() << std::endl;\r
- // return;\r
- // }\r
-\r
- // c.connect(con);\r
- // }\r
-\r
- // void update()\r
- // {\r
- // c.run_one();\r
- // }\r
-\r
-\r
-\r
-\r
-\r
mg_mgr mgr;\r
mg_connection *c = nullptr;\r
\r
bool done = false;\r
\r
static void cb(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {\r
- if (ev == MG_EV_ERROR || ev == MG_EV_CLOSE) {\r
- MessageBoxA(NULL, "", "Error", MB_OK);\r
- } else if (ev == MG_EV_WS_OPEN) {\r
- //mg_ws_send(c, "hello", 5, WEBSOCKET_OP_TEXT);\r
+ if (ev == MG_EV_WS_OPEN) {\r
} else if (ev == MG_EV_WS_MSG) {\r
struct mg_ws_message *wm = (struct mg_ws_message *) ev_data;\r
std::string jsonStr(wm->data.ptr, wm->data.len);\r
}}\r
};\r
auto responseStr = response.dump();\r
- MessageBoxA(NULL,\r
- (std::string("is_client") + std::to_string(c->is_client) +\r
- std::string(" is_accepted") + std::to_string(c->is_accepted) +\r
- std::string(" is_readable") + std::to_string(c->is_readable) +\r
- std::string(" is_writable") + std::to_string(c->is_writable)).c_str(),\r
- "", MB_OK);\r
- mg_ws_send(c, "{\"op\":1,\"d\":{\"rpcVersion\":1}}", 29, WEBSOCKET_OP_TEXT);\r
+ mg_ws_send(c, responseStr.c_str(), responseStr.size(), WEBSOCKET_OP_TEXT);\r
}\r
else if (op == 2)\r
{\r
}\r
}\r
\r
- if (ev == MG_EV_ERROR || ev == MG_EV_CLOSE) {\r
+ if (ev == MG_EV_ERROR) {\r
+ MessageBoxA(NULL, "", "Error", MB_OK);\r
+ done = true;\r
+ }\r
+ if (ev == MG_EV_CLOSE) {\r
+ MessageBoxA(NULL, "", "Close", MB_OK);\r
done = true;\r
}\r
}\r
{\r
if (c && !done)\r
mg_mgr_poll(&mgr, 10);\r
- else\r
- MessageBoxA(NULL, "cant update", "Nio", MB_OK);\r
}\r
\r
- void identify()\r
+ void sendRequest(std::string requestType)\r
{\r
- MessageBoxA(NULL,\r
- (std::string("is_client") + std::to_string(c->is_client) +\r
- std::string(" is_accepted") + std::to_string(c->is_accepted) +\r
- std::string(" is_readable") + std::to_string(c->is_readable) +\r
- std::string(" is_writable") + std::to_string(c->is_writable)).c_str(),\r
- "", MB_OK);\r
- mg_ws_send(c, "{\"op\":1,\"d\":{\"rpcVersion\":1}}", 29, WEBSOCKET_OP_TEXT);\r
+ json request = { { "op", 6 },\r
+ { "d",\r
+ {\r
+ { "requestType", requestType },\r
+ { "requestId", std::to_string(NULL).c_str() }\r
+ } } };\r
+ auto requestStr = request.dump();\r
+ mg_ws_send(c, requestStr.c_str(), requestStr.size(), WEBSOCKET_OP_TEXT);\r
}\r
}
\ No newline at end of file