uiTimer() Use TimerHandler pointers directly as Windows timer IDs

This commit is contained in:
cody271 2017-08-26 15:05:53 -07:00
parent c9d11a85cc
commit d99549ec18
3 changed files with 9 additions and 12 deletions

View File

@ -1,7 +1,6 @@
// 6 april 2015
#include "uipriv_windows.hpp"
std::map<UINT_PTR, TimerHandler> 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);
}

View File

@ -113,7 +113,6 @@ private:
};
extern int registerMessageFilter(void);
extern void unregisterMessageFilter(void);
extern std::map<UINT_PTR, TimerHandler> timerHandlers;
// parent.cpp
extern void paintContainerBackground(HWND hwnd, HDC dc, RECT *paintRect);

View File

@ -18,7 +18,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;
@ -38,11 +38,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;
}