diff --git a/api.cpp b/api.cpp index e7f29109..9ae70934 100644 --- a/api.cpp +++ b/api.cpp @@ -223,6 +223,7 @@ class Application { return; } + SetWindowLongPtr(hwnd, GWLP_USERDATA, reinterpret_cast(this)); MoveWindow(hwnd, 0, 0, 400, 600, TRUE); HWND running_button = CreateWindow( @@ -285,6 +286,8 @@ class Application { } static LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { + Application* app = reinterpret_cast(GetWindowLongPtr(hwnd, GWLP_USERDATA)); + switch (uMsg) { case WM_COMMAND: if (LOWORD(wParam) == Widgets::RUNNING) { @@ -295,7 +298,7 @@ class Application { } std::string status = running ? "Stop" : "Start"; - SetWindowText(widgets[Widgets::RUNNING], status.c_str()); + SetWindowText(app->widgets[Widgets::RUNNING], status.c_str()); } if (LOWORD(wParam) == Widgets::EXIT) { DestroyWindow(hwnd); @@ -304,7 +307,7 @@ class Application { case WM_TIMER: if (wParam == 1) { - update(); + app->update(); } return 0;