Skip to content

Commit

Permalink
uiTimer() Use TimerHandler pointers directly as Windows timer IDs
Browse files Browse the repository at this point in the history
  • Loading branch information
cody271 committed Aug 27, 2017
1 parent 6e2a1ba commit 8bfda78
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
10 changes: 4 additions & 6 deletions windows/main.cpp
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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);
}
1 change: 0 additions & 1 deletion windows/uipriv_windows.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ struct TimerHandler {
};
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);
Expand Down
10 changes: 5 additions & 5 deletions windows/utilwin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down

0 comments on commit 8bfda78

Please sign in to comment.