From bea4e9f8740c1bf3ebe80d95ab6e749cfb5de605 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Sun, 7 Aug 2022 00:23:05 +0200 Subject: Simplify WaitFor. --- c/main.cpp | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/c/main.cpp b/c/main.cpp index 237cc22..449863b 100644 --- a/c/main.cpp +++ b/c/main.cpp @@ -382,7 +382,7 @@ LRESULT CALLBACK WndProc(const HWND hWnd, const UINT uMsg, const WPARAM wParam, return 0; } -void HandleMainMenu(const HWND hWnd, WORD command) +void HandleMainMenu(const HWND hWnd, const WORD command) { switch (command) { case IDM_FILE_EXIT: @@ -438,7 +438,7 @@ void HandleMainMenu(const HWND hWnd, WORD command) } } -void HandleContextMenu(const HWND, WORD command) +void HandleContextMenu(const HWND, const WORD command) { int cNotFound = 0; @@ -498,12 +498,11 @@ void HandleContextMenu(const HWND, WORD command) void WaitFor(const char* mod, const char* pred) { - static atom_t aThread; - static bool bActive; - static int iTimer; static WcharPtr activePred; + static UINT_PTR iTimer; + static atom_t aThread; - if (bActive) { + if (activePred) { wchar_t msg[256] = {0}; Swprintf(msg, L"Another task (%s) is active. " L"Do you want to cancel the existing task and start a new one?", @@ -511,7 +510,7 @@ void WaitFor(const char* mod, const char* pred) if (EBMessageBox(msg, L"Error", MB_YESNO|MB_ICONWARNING) != IDYES) return; KillTimer(nullptr, iTimer); - bActive = false; + activePred = nullptr; g_elv->Update(); } @@ -530,17 +529,15 @@ void WaitFor(const char* mod, const char* pred) } else { KillTimer(nullptr, iTimer); i = 0; - bActive = false; + activePred = nullptr; g_elv->Update(); } }; Plx(mod,"thread_create",pred,&aThread); SendMessage(g_hWndStatus, SB_SETTEXT, MAKEWPARAM(1,0), reinterpret_cast(L".")); - if (Prefer(iTimer = SetTimer(nullptr, -1, 500, proc))) { + if (Prefer(iTimer = SetTimer(nullptr, -1, 500, proc))) activePred = WcharPtr::FromNarrow(pred); - bActive = true; - } } INT_PTR CALLBACK AboutDlgProc(const HWND hWnd, const UINT uMsg, const WPARAM wParam, const LPARAM) -- cgit v1.2.3