Implement uiTimer() for Windows

This commit is contained in:
cody271 2017-08-20 18:31:41 -07:00
parent 68e1223e4d
commit b1210165a0
3 changed files with 26 additions and 0 deletions

View File

@ -1,6 +1,7 @@
// 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)
@ -131,4 +132,8 @@ void uiQueueMain(void (*f)(void *data), void *data)
void uiTimer(int milliseconds, int (*f)(void *data), void *data)
{
UINT_PTR id = timerHandlers.size() + 1;
if (SetTimer(utilWindow, id, milliseconds, NULL) == 0)
logLastError(L"SetTimer()");
timerHandlers[id] = TimerHandler(f, data);
}

View File

@ -77,6 +77,17 @@ extern void setWindowInsertAfter(HWND hwnd, HWND insertAfter);
extern HWND getDlgItem(HWND hwnd, int id);
extern void invalidateRect(HWND hwnd, RECT *r, BOOL erase);
struct TimerHandler {
int(*f)(void *data);
void *data;
TimerHandler() {}
TimerHandler(int(*f)(void *data), void *data) {
this->f = f;
this->data = data;
}
};
extern std::map<UINT_PTR, TimerHandler> timerHandlers;
// text.cpp
extern WCHAR *windowTextAndLen(HWND hwnd, LRESULT *len);
extern WCHAR *windowText(HWND hwnd);

View File

@ -18,6 +18,7 @@ static LRESULT CALLBACK utilWindowWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, L
{
void (*qf)(void *);
LRESULT lResult;
UINT_PTR id;
if (handleParentMessages(hwnd, uMsg, wParam, lParam, &lResult) != FALSE)
return lResult;
@ -36,6 +37,15 @@ static LRESULT CALLBACK utilWindowWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, L
qf = (void (*)(void *)) wParam;
(*qf)((void *) lParam);
return 0;
case WM_TIMER:
id = (UINT_PTR)wParam;
TimerHandler timer = timerHandlers[id];
if (!timer.f(timer.data)) {
if (!KillTimer(utilWindow, id))
logLastError(L"KillTimer()");
timerHandlers.erase(id);
}
return 0;
}
return DefWindowProcW(hwnd, uMsg, wParam, lParam);
}