diff options
Diffstat (limited to 'src/main.cpp')
| -rw-r--r-- | src/main.cpp | 122 |
1 files changed, 55 insertions, 67 deletions
diff --git a/src/main.cpp b/src/main.cpp index a590411..805932d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -87,60 +87,48 @@ checkForegroundProcess(std::string exeName) bool recording = false;
HANDLE process = NULL;
-int WINAPI
-WinMain(HINSTANCE hInstance,
- HINSTANCE hPrevInstance,
- LPSTR lpCmdLine,
- int nCmdShow)
+// int WINAPI
+// WinMain(HINSTANCE hInstance,
+// HINSTANCE hPrevInstance,
+// LPSTR lpCmdLine,
+// int nCmdShow)
+int main(int argc, char **argv)
{
- HWND window = win::Window("Title", "MyWindowClass", hInstance);
-
- lay_id row1 = lay_item(&win::_::ctx);
- lay_insert(&win::_::ctx, win::_::root, row1);
- lay_set_size_xy(&win::_::ctx, row1, 0, 25);
- lay_set_behave(&win::_::ctx, row1, LAY_LEFT);
- lay_set_contain(&win::_::ctx, row1, LAY_ROW);
- lay_set_margins_ltrb(&win::_::ctx, row1, 5, 5, 5, 5);
- lay_id row2 = lay_item(&win::_::ctx);
- lay_insert(&win::_::ctx, win::_::root, row2);
- 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);
- lay_set_contain(&win::_::ctx, col1, LAY_COLUMN);
- lay_set_margins_ltrb(&win::_::ctx, col1, 5, 0, 5, 0);
-
- HWND cbWindowTitle = win::CheckBox(window, "Window Title", row1, 100, 25, 0, 0);
- HWND cbFullscreenWindow = win::CheckBox(window, "Any Fullscreen Application", row1, 200, 25, 0, 0);
-
- HWND btnConnect = win::Button(window, "Connect", row1, 100, 25, 0, 0);
- win::Callback(btnConnect, BN_CLICKED, [&]() {
- ws::connect("ws://127.0.0.1:4444");
- });
+ //win::Window window("Title", "MyWindowClass", hInstance);
+ win::Window window("Title", "MyWindowClass", GetModuleHandle(0));
- win::Callback(cbWindowTitle, BN_CLICKED, [&]() {
- SendMessageA(cbWindowTitle, BM_SETCHECK, SendMessageA(cbWindowTitle, BM_GETCHECK, 0, 0) ? BST_UNCHECKED : BST_CHECKED, 0);
- });
- win::Callback(cbFullscreenWindow, BN_CLICKED, [&]() {
- SendMessageA(cbFullscreenWindow, BM_SETCHECK, SendMessageA(cbFullscreenWindow, BM_GETCHECK, 0, 0) ? BST_UNCHECKED : BST_CHECKED, 0);
+ lay_context *ctx = &window.ctx;
+ lay_id root = window.lId;
+
+ win::Hwnd row1(&window, &window, 0, 0, 0, 25, LAY_ROW, LAY_LEFT);
+ lay_set_margins_ltrb(ctx, row1.lId, 5, 5, 5, 5);
+ win::Hwnd row2(&window, &window, 0, 0, 0, 0, LAY_ROW, LAY_FILL);
+ lay_set_margins_ltrb(ctx, row2.lId, 5, 5, 5, 5);
+
+ win::CheckBox cbWindowTitle(&window, &row1, "Window Title", 100, 25, 0, 0);
+ win::CheckBox cbFullscreenWindow(&window, &row1, "Any Fullscreen Application", 200, 25, 0, 0);
+
+ win::Button btnConnect(&window, &row1, "Connect", 100, 25, 0, 0);
+ btnConnect.onClick([&]() {
+ ws::connect("ws://127.0.0.1:4444");
});
- 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);
- win::AddStyle(lstMonitoredProcesses, WS_VSCROLL);
-
- HWND btnUpdateWindows = win::Button(window, "Update", col1, 85, 25, 0, 0);
- HWND btnStartMonitoringName = win::Button(window, "Exe name >>", col1, 85, 25, 0, 0);
- HWND btnStartMonitoringPath = win::Button(window, "Full path >>", col1, 85, 25, 0, 0);
- HWND btnStopMonitoring = win::Button(window, "Remove", col1, 85, 25, 0, 0);
- win::Callback(btnUpdateWindows, BN_CLICKED, [&]() {
- win::ListClear(lstActiveProcesses);
+ win::ListBox lstActiveProcesses(&window, &row2, 0, 0, 0, LAY_FILL);
+
+ win::Hwnd col1(&window, &row2, 0, 0, 80, 0, LAY_COLUMN, LAY_VCENTER);
+ lay_set_margins_ltrb(ctx, col1.lId, 5, 0, 5, 0);
+
+ win::ListBox lstMonitoredProcesses(&window, &row2, 0, 0, 0, LAY_FILL);
+ lstActiveProcesses.addStyle(WS_VSCROLL);
+ lstMonitoredProcesses.addStyle(WS_VSCROLL);
+
+ win::Button btnUpdateWindows(&window, &col1, "Update", 85, 25, 0, 0);
+ win::Button btnStartMonitoringName(&window, &col1, "Exe name >>", 85, 25, 0, 0);
+ win::Button btnStartMonitoringPath(&window, &col1, "Full path >>", 85, 25, 0, 0);
+ win::Button btnStopMonitoring(&window, &col1, "Remove", 85, 25, 0, 0);
+ btnUpdateWindows.onClick([&]() {
+ lstActiveProcesses.clear();
for (HWND hwnd = GetTopWindow(NULL); hwnd != nullptr;
hwnd = GetNextWindow(hwnd, GW_HWNDNEXT)) {
if (!IsWindowVisible(hwnd))
@@ -151,44 +139,44 @@ WinMain(HINSTANCE hInstance, char str[1024];
if (GetModuleFileNameExA(getHwndProcess(hwnd), 0, str, 1024) != 0 &&
- win::ListFindString(lstActiveProcesses, str) == LB_ERR) {
- win::ListAddString(lstActiveProcesses, str);
+ lstActiveProcesses.findString(str) == LB_ERR) {
+ lstActiveProcesses.addString(str);
}
}
});
- win::Callback(btnStartMonitoringName, BN_CLICKED, [&]() {
- int sel = win::ListGetSelectedIndex(lstActiveProcesses);
+ btnStartMonitoringName.onClick([&]() {
+ int sel = lstActiveProcesses.getSelectedIndex();
if (sel < 0) return;
- std::string selStr = win::ListGetText(lstActiveProcesses, sel);
+ std::string selStr = lstActiveProcesses.getText(sel);
char *filename = new char[selStr.size()];
std::memcpy(filename, selStr.c_str(), selStr.size());
PathStripPathA(filename);
- if (win::ListFindString(lstMonitoredProcesses, std::string(filename)) == LB_ERR)
- win::ListAddString(lstMonitoredProcesses, std::string(filename));
+ if (lstMonitoredProcesses.findString(std::string(filename)) == LB_ERR)
+ lstMonitoredProcesses.addString(std::string(filename));
delete[] filename;
});
- win::Callback(btnStartMonitoringPath, BN_CLICKED, [&]() {
- int sel = win::ListGetSelectedIndex(lstActiveProcesses);
+ btnStartMonitoringPath.onClick([&]() {
+ int sel = lstActiveProcesses.getSelectedIndex();
if (sel < 0) return;
- std::string selStr = win::ListGetText(lstActiveProcesses, sel);
- if (win::ListFindString(lstMonitoredProcesses, selStr) == LB_ERR)
- win::ListAddString(lstMonitoredProcesses, selStr);
+ std::string selStr = lstActiveProcesses.getText(sel);
+ if (lstMonitoredProcesses.findString(selStr) == LB_ERR)
+ lstMonitoredProcesses.addString(selStr);
});
- win::Callback(btnStopMonitoring, BN_CLICKED, [&]() {
- int sel = win::ListGetSelectedIndex(lstMonitoredProcesses);
+ btnStopMonitoring.onClick([&]() {
+ int sel = lstMonitoredProcesses.getSelectedIndex();
if (sel < 0) return;
- win::ListRemove(lstMonitoredProcesses, sel);
+ lstMonitoredProcesses.remove(sel);
});
- win::ShowWindow(window);
+ window.show();
ws::init();
- SetTimer(window, 10123, 100, [](HWND, UINT, UINT_PTR, DWORD) {
+ SetTimer(window.hwnd, 10123, 100, [](HWND, UINT, UINT_PTR, DWORD) {
if (!recording) {
if (checkForegroundProcess("League of Legends.exe")) {
recording = true;
@@ -204,7 +192,7 @@ WinMain(HINSTANCE hInstance, }
});
- while (win::UpdateWindow(window)) {
+ while (window.update()) {
ws::update();
}
}
|
