diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/main.cpp | 38 | ||||
| -rw-r--r-- | src/win.h | 104 | ||||
| -rw-r--r-- | src/ws.h | 101 |
3 files changed, 85 insertions, 158 deletions
diff --git a/src/main.cpp b/src/main.cpp index f4a47f3..5056acf 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -20,13 +20,13 @@ void
startRecording()
{
- MessageBoxA(NULL, "Start", "Start Start", MB_OK);
+ ws::sendRequest("StartRecord");
}
void
stopRecording()
{
- MessageBoxA(NULL, "Stop", "Stop Stop", MB_OK);
+ ws::sendRequest("StopRecord");
}
bool
@@ -74,17 +74,20 @@ checkFullscreenWindow() }
bool
-checkNotepadWindow()
+checkForegroundProcess(std::string exeName)
{
HWND fgHwnd = GetForegroundWindow();
HANDLE fgHandle = getHwndProcess(fgHwnd);
char filename[1024];
int len = GetModuleFileNameExA(fgHandle, NULL, filename, 1024);
+ PathStripPathA(filename);
- return strcmp(filename, "C:\\Windows\\System32\\notepad.exe") == 0;
+ return strcmp(filename, exeName.c_str()) == 0;
}
+bool recording = false;
+HANDLE process = NULL;
int WINAPI
WinMain(HINSTANCE hInstance,
@@ -92,8 +95,6 @@ WinMain(HINSTANCE hInstance, LPSTR lpCmdLine,
int nCmdShow)
{
- bool recording = false;
- HANDLE process = NULL;
HWND window = win::Window("Title", "MyWindowClass", hInstance);
@@ -108,6 +109,7 @@ WinMain(HINSTANCE hInstance, lay_set_size_xy(&win::_::ctx, row2, 0, 0);
lay_set_behave(&win::_::ctx, row2, LAY_FILL);
lay_set_contain(&win::_::ctx, row2, LAY_ROW);
+ lay_set_margins_ltrb(&win::_::ctx, row2, 5, 5, 5, 5);
lay_id col1 = lay_item(&win::_::ctx);
lay_set_size_xy(&win::_::ctx, col1, 80, 0);
lay_set_behave(&win::_::ctx, col1, LAY_VCENTER);
@@ -121,11 +123,6 @@ WinMain(HINSTANCE hInstance, win::Callback(btnConnect, BN_CLICKED, [&]() {
ws::connect("ws://127.0.0.1:4444");
});
-
- HWND btnIdentify = win::Button(window, "Identify", row1, 100, 25, 0, 0);
- win::Callback(btnIdentify, BN_CLICKED, [&]() {
- ws::identify();
- });
win::Callback(cbWindowTitle, BN_CLICKED, [&]() {
SendMessageA(cbWindowTitle, BM_SETCHECK, SendMessageA(cbWindowTitle, BM_GETCHECK, 0, 0) ? BST_UNCHECKED : BST_CHECKED, 0);
@@ -134,7 +131,7 @@ WinMain(HINSTANCE hInstance, SendMessageA(cbFullscreenWindow, BM_SETCHECK, SendMessageA(cbFullscreenWindow, BM_GETCHECK, 0, 0) ? BST_UNCHECKED : BST_CHECKED, 0);
});
- HWND lstActiveProcesses = win::ListBox(window, row2, 0, 0, 0, LAY_FILL);
+ HWND lstActiveProcesses = win::ListView(window, row2, 0, 0, 0, LAY_FILL);
lay_insert(&win::_::ctx, row2, col1);
HWND lstMonitoredProcesses = win::ListBox(window, row2, 0, 0, 0, LAY_FILL);
win::AddStyle(lstActiveProcesses, WS_VSCROLL);
@@ -189,28 +186,27 @@ WinMain(HINSTANCE hInstance, win::ListRemove(lstMonitoredProcesses, sel);
});
-
- win::ShowNotificationIcon(hInstance, window);
-
win::ShowWindow(window);
ws::init();
- while (win::UpdateWindow(window)) {
- ws::update();
-
+ SetTimer(window, 10123, 100, [](HWND, UINT, UINT_PTR, DWORD) {
if (!recording) {
- if (checkNotepadWindow()) {
+ if (checkForegroundProcess("League of Legends.exe")) {
+ recording = true;
process = getHwndProcess(GetForegroundWindow());
startRecording();
- recording = true;
}
} else {
if (!checkProcessRunning(process)) {
+ recording = false;
process = NULL;
stopRecording();
- recording = false;
}
}
+ });
+
+ while (win::UpdateWindow(window)) {
+ ws::update();
}
}
@@ -14,46 +14,24 @@ processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") using std::string;
namespace win {
-struct Length
-{
- int pixel;
- float percent;
-};
-struct Size
-{
- Length x, y, w, h;
- int getX(HWND hwnd)
- {
- RECT rect;
- GetClientRect(hwnd, &rect);
- return x.percent * (rect.right - rect.left) + x.pixel;
- }
- int getY(HWND hwnd)
- {
- RECT rect;
- GetClientRect(hwnd, &rect);
- return y.percent * (rect.bottom - rect.top) + y.pixel;
- }
- int getW(HWND hwnd)
- {
- RECT rect;
- GetClientRect(hwnd, &rect);
- return w.percent * (rect.right - rect.left) + w.pixel;
- }
- int getH(HWND hwnd, int _w, int _h)
- {
- RECT rect;
- GetWindowRect(hwnd, &rect);
- return h.percent * (rect.bottom - rect.top) + h.pixel;
- }
-};
-
namespace _ {
using CallbackFn = std::function<void()>;
std::map<HWND, std::map<WORD, CallbackFn>> handlers;
std::map<HWND, lay_id> lIds;
NOTIFYICONDATA niData = { 0 };
+void
+ShowNotificationIcon()
+{
+ Shell_NotifyIconA(NIM_ADD, &_::niData);
+ Shell_NotifyIconA(NIM_SETVERSION, &_::niData);
+}
+
+void
+HideNotificationIcon()
+{
+ Shell_NotifyIconA(NIM_DELETE, &_::niData);
+}
lay_context ctx;
lay_id root;
@@ -72,9 +50,8 @@ WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) break;
case WM_SIZE:
if (wParam == SIZE_MINIMIZED) {
+ ShowNotificationIcon();
ShowWindow(hwnd, false);
- SetForegroundWindow(hwnd);
- SetActiveWindow(hwnd);
}
else {
lay_set_size_xy(&_::ctx, _::root, LOWORD(lParam), HIWORD(lParam));
@@ -105,8 +82,12 @@ WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) case WM_NOTIFY:
break;
case WM_APP + 1:
- if (LOWORD(lParam) == NIN_SELECT)
+ if (LOWORD(lParam) == NIN_SELECT) {
+ HideNotificationIcon();
ShowWindow(hwnd, true);
+ SetForegroundWindow(hwnd);
+ SetActiveWindow(hwnd);
+ }
break;
case WM_CTLCOLORSTATIC:
return (LONG)GetStockObject(WHITE_BRUSH);
@@ -123,20 +104,6 @@ WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) }
}
-void
-ShowNotificationIcon(HINSTANCE hInstance, HWND hwnd)
-{
- _::niData.cbSize = sizeof(_::niData);
- _::niData.uID = 12345;
- _::niData.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
- _::niData.hIcon = LoadIconA(nullptr, IDI_WINLOGO);
- _::niData.hWnd = hwnd;
- _::niData.uCallbackMessage = WM_APP+1;
- _::niData.uVersion = NOTIFYICON_VERSION_4;
-
- Shell_NotifyIconA(NIM_ADD, &_::niData);
- Shell_NotifyIconA(NIM_SETVERSION, &_::niData);
-}
void
Callback(HWND hwnd, WORD ev, std::function<void()> cb)
@@ -165,9 +132,8 @@ Window(string title, string className, HINSTANCE hInstance) lay_init_context(&_::ctx);
_::root = lay_item(&_::ctx);
lay_set_contain(&_::ctx, _::root, LAY_COLUMN);
- lay_set_margins_ltrb(&_::ctx, _::root, 5, 5, 5, 5);
- return CreateWindowA(className.c_str(),
+ HWND result = CreateWindowA(className.c_str(),
title.c_str(),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
@@ -178,6 +144,16 @@ Window(string title, string className, HINSTANCE hInstance) nullptr,
hInstance,
nullptr);
+
+ _::niData.cbSize = sizeof(_::niData);
+ _::niData.uID = 12345;
+ _::niData.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
+ _::niData.hIcon = LoadIconA(nullptr, IDI_WINLOGO);
+ _::niData.hWnd = result;
+ _::niData.uCallbackMessage = WM_APP+1;
+ _::niData.uVersion = NOTIFYICON_VERSION_4;
+
+ return result;
}
bool
@@ -289,6 +265,28 @@ void ListRemove(HWND hwnd, int index) }
HWND
+ListView(HWND hwnd, lay_id parent, lay_scalar w, lay_scalar h, uint32_t contain, uint32_t behave)
+{
+ lay_id lId = lay_item(&_::ctx);
+ lay_insert(&_::ctx, parent, lId);
+ lay_set_size_xy(&_::ctx, lId, w, h);
+ lay_set_contain(&_::ctx, lId, contain);
+ lay_set_behave(&_::ctx, lId, behave);
+
+ HWND result = CreateWindowExA(0,
+ WC_LISTVIEWA,
+ "",
+ WS_VISIBLE | WS_CHILD | WS_BORDER | WS_VSCROLL,
+ 0, 0, 0, 0,
+ hwnd,
+ nullptr,
+ nullptr,
+ nullptr);
+ _::lIds[result] = lId;
+ return result;
+}
+
+HWND
CheckBox(HWND hwnd, string title, lay_id parent, lay_scalar w, lay_scalar h, uint32_t contain, uint32_t behave)
{
lay_id lId = lay_item(&_::ctx);
@@ -1,10 +1,3 @@ -// #define _WEBSOCKETPP_CPP11_INTERNAL_
-// #define ASIO_STANDALONE
-// #include <websocketpp/config/asio_no_tls_client.hpp>
-// #include <websocketpp/client.hpp>
-
-// using client = websocketpp::client<websocketpp::config::asio_client>;
-
#include "mongoose.h"
#include "json.hpp"
@@ -14,71 +7,13 @@ using json = nlohmann::json; namespace ws
{
- // client c;
-
- // void on_message(websocketpp::connection_hdl hdl, client::message_ptr msg) {
- // auto j = json::parse(msg->get_payload());
- // int op = j["op"].get<int>();
-
- // if (op == 0) {
- // json response = { { "op", 1 },
- // { "d", {
- // { "rpcVersion", 1 },
- // } } };
- // auto responseStr = response.dump();
- // websocketpp::lib::error_code ec;
- // c.send(hdl, responseStr, websocketpp::frame::opcode::TEXT, ec);
- // if (ec)
- // MessageBoxA(NULL, ec.message().c_str(), "error", MB_OK);
- // } else if (op == 2) {
- // MessageBoxA(NULL, "hura", "connected", MB_OK);
- // }
- // }
-
- // void init()
- // {
- // c.set_access_channels(websocketpp::log::alevel::all);
- // c.clear_access_channels(websocketpp::log::alevel::frame_payload);
- // c.set_error_channels(websocketpp::log::elevel::all);
-
- // // Initialize ASIO
- // c.init_asio();
-
- // // Register our message handler
- // c.set_message_handler(&on_message);
- // }
-
- // void connect(std::string address)
- // {
- // websocketpp::lib::error_code ec;
- // client::connection_ptr con = c.get_connection(address, ec);
- // if (ec) {
- // std::cout << "could not create connection because: " << ec.message() << std::endl;
- // return;
- // }
-
- // c.connect(con);
- // }
-
- // void update()
- // {
- // c.run_one();
- // }
-
-
-
-
-
mg_mgr mgr;
mg_connection *c = nullptr;
bool done = false;
static void cb(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
- if (ev == MG_EV_ERROR || ev == MG_EV_CLOSE) {
- MessageBoxA(NULL, "", "Error", MB_OK);
- } else if (ev == MG_EV_WS_OPEN) {
- //mg_ws_send(c, "hello", 5, WEBSOCKET_OP_TEXT);
+ if (ev == MG_EV_WS_OPEN) {
} else if (ev == MG_EV_WS_MSG) {
struct mg_ws_message *wm = (struct mg_ws_message *) ev_data;
std::string jsonStr(wm->data.ptr, wm->data.len);
@@ -93,13 +28,7 @@ namespace ws }}
};
auto responseStr = response.dump();
- MessageBoxA(NULL,
- (std::string("is_client") + std::to_string(c->is_client) +
- std::string(" is_accepted") + std::to_string(c->is_accepted) +
- std::string(" is_readable") + std::to_string(c->is_readable) +
- std::string(" is_writable") + std::to_string(c->is_writable)).c_str(),
- "", MB_OK);
- mg_ws_send(c, "{\"op\":1,\"d\":{\"rpcVersion\":1}}", 29, WEBSOCKET_OP_TEXT);
+ mg_ws_send(c, responseStr.c_str(), responseStr.size(), WEBSOCKET_OP_TEXT);
}
else if (op == 2)
{
@@ -107,7 +36,12 @@ namespace ws }
}
- if (ev == MG_EV_ERROR || ev == MG_EV_CLOSE) {
+ if (ev == MG_EV_ERROR) {
+ MessageBoxA(NULL, "", "Error", MB_OK);
+ done = true;
+ }
+ if (ev == MG_EV_CLOSE) {
+ MessageBoxA(NULL, "", "Close", MB_OK);
done = true;
}
}
@@ -126,18 +60,17 @@ namespace ws {
if (c && !done)
mg_mgr_poll(&mgr, 10);
- else
- MessageBoxA(NULL, "cant update", "Nio", MB_OK);
}
- void identify()
+ void sendRequest(std::string requestType)
{
- MessageBoxA(NULL,
- (std::string("is_client") + std::to_string(c->is_client) +
- std::string(" is_accepted") + std::to_string(c->is_accepted) +
- std::string(" is_readable") + std::to_string(c->is_readable) +
- std::string(" is_writable") + std::to_string(c->is_writable)).c_str(),
- "", MB_OK);
- mg_ws_send(c, "{\"op\":1,\"d\":{\"rpcVersion\":1}}", 29, WEBSOCKET_OP_TEXT);
+ json request = { { "op", 6 },
+ { "d",
+ {
+ { "requestType", requestType },
+ { "requestId", std::to_string(NULL).c_str() }
+ } } };
+ auto requestStr = request.dump();
+ mg_ws_send(c, requestStr.c_str(), requestStr.size(), WEBSOCKET_OP_TEXT);
}
}
\ No newline at end of file |
