Skip to content

Commit

Permalink
Use running toggle instead of two buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
eschan145 committed Nov 3, 2024
1 parent 9a2039a commit 5c81482
Showing 1 changed file with 18 additions and 25 deletions.
43 changes: 18 additions & 25 deletions api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@ Compile with g++ -shared -o api.dll api.cpp -Ofast -fPIC -shared
using namespace std;
namespace fs = std::filesystem;

std::vector<HWND> widgets;

const char* FOLDER_PATH = "C:/Program Files/DyKnow/Cloud/7.10.22.9";
const int BUTTON_WIDTH = 150;
const int BUTTON_HEIGHT = 30;

namespace Widgets {
enum Button {
START = 1,
STOP = 2
RUNNING = 0,
STOP
};
}

Expand Down Expand Up @@ -173,11 +175,16 @@ __declspec(dllexport) int __stdcall bsod()
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
switch (uMsg) {
case WM_COMMAND:
if (LOWORD(wParam) == Widgets::START) {
start_monitoring(FOLDER_PATH);
}
else if (LOWORD(wParam) == Widgets::STOP) {
stop_monitoring();
if (LOWORD(wParam) == Widgets::RUNNING) {
running = !running;
std::string status = running ? "Running" : "Stopped";
SetWindowText(widgets[Widgets::RUNNING], status.c_str());

if (running) {
start_monitoring(FOLDER_PATH);
} else {
stop_monitoring();
}
}
break;
case WM_DESTROY:
Expand All @@ -188,7 +195,6 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
}

void create_window() {
std::vector<HWND> widgets;
const char CLASS_NAME[] = "DieKnow";

WNDCLASS wc = {};
Expand Down Expand Up @@ -226,33 +232,20 @@ void create_window() {
return;
}

HWND start_button = CreateWindow(
HWND running_button = CreateWindow(
"BUTTON",
"Start monitoring",
"Running",
WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
10,
10,
BUTTON_WIDTH,
BUTTON_HEIGHT,
hwnd,
(HMENU)Widgets::START,
wc.hInstance,
NULL);

HWND stop_button = CreateWindow(
"BUTTON",
"Stop monitoring",
WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
10,
50,
BUTTON_WIDTH,
BUTTON_HEIGHT,
hwnd,
(HMENU)Widgets::STOP,
(HMENU)Widgets::RUNNING,
wc.hInstance,
NULL);

widgets.push_back(start_button);
widgets.push_back(running_button);
widgets.push_back(stop_button);

for (HWND widget : widgets) {
Expand Down

0 comments on commit 5c81482

Please sign in to comment.