From 8bfda78c6f7a3f211391d86eee2f3febf810bc6b Mon Sep 17 00:00:00 2001 From: cody271 Date: Sat, 26 Aug 2017 15:05:53 -0700 Subject: [PATCH] uiTimer() Use TimerHandler pointers directly as Windows timer IDs --- windows/main.cpp | 10 ++++------ windows/uipriv_windows.hpp | 1 - windows/utilwin.cpp | 10 +++++----- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/windows/main.cpp b/windows/main.cpp index 2443714ea..65e49dbb7 100644 --- a/windows/main.cpp +++ b/windows/main.cpp @@ -1,7 +1,6 @@ // 6 april 2015 #include "uipriv_windows.hpp" -std::map timerHandlers; static HHOOK filter; static LRESULT CALLBACK filterProc(int code, WPARAM wParam, LPARAM lParam) @@ -132,10 +131,9 @@ void uiQueueMain(void (*f)(void *data), void *data) void uiTimer(int milliseconds, int (*f)(void *data), void *data) { - UINT_PTR id = timerHandlers.size() + 1; - while (timerHandlers.find(id) != timerHandlers.end()) - id++; - if (SetTimer(utilWindow, id, milliseconds, NULL) == 0) + UINT_PTR timer; + + timer = (UINT_PTR) new TimerHandler(f, data); + if (SetTimer(utilWindow, timer, milliseconds, NULL) == 0) logLastError(L"SetTimer()"); - timerHandlers[id] = TimerHandler(f, data); } diff --git a/windows/uipriv_windows.hpp b/windows/uipriv_windows.hpp index 126f3628c..2e3c65f4e 100644 --- a/windows/uipriv_windows.hpp +++ b/windows/uipriv_windows.hpp @@ -112,7 +112,6 @@ struct TimerHandler { }; extern int registerMessageFilter(void); extern void unregisterMessageFilter(void); -extern std::map timerHandlers; // parent.cpp extern void paintContainerBackground(HWND hwnd, HDC dc, RECT *paintRect); diff --git a/windows/utilwin.cpp b/windows/utilwin.cpp index a1d1ad64b..d27059be9 100644 --- a/windows/utilwin.cpp +++ b/windows/utilwin.cpp @@ -17,7 +17,7 @@ static LRESULT CALLBACK utilWindowWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, L { void (*qf)(void *); LRESULT lResult; - UINT_PTR id; + TimerHandler *timer; if (handleParentMessages(hwnd, uMsg, wParam, lParam, &lResult) != FALSE) return lResult; @@ -37,11 +37,11 @@ static LRESULT CALLBACK utilWindowWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, L (*qf)((void *) lParam); return 0; case WM_TIMER: - id = (UINT_PTR)wParam; - if (!timerHandlers[id]()) { - if (!KillTimer(utilWindow, id)) + timer = (TimerHandler *) wParam; + if (!(*timer)()) { + if (!KillTimer(utilWindow, (UINT_PTR) timer)) logLastError(L"KillTimer()"); - timerHandlers.erase(id); + delete timer; } return 0; }